1
這裏是我的HTML類:jQuery的去除。點擊
<a href="#">Read more</a>
<div class="moreDetails">
<p class="additionalText">Some text help here, random length.</p>
<p class="author">
<span class="bolder"><a href="minidashboard.php?user_url=http://url.people/1332517">Name</a>
</span>
</p>
<div class="replies">
<span>
<a href="topic.php?id=http://url/topics/1049198">1</a>
</span>
</div>
林則使用jQuery類添加到.additionalText
股利時,其文字是超過36個字符長。
的jQuery:
$('.moreDetails p.additionalText').filter(function() {
if ($(this).text().length > 32) {
$(this).addClass('trim');
}
});
時<a href="#">Read more</a>
點擊類.trim
被刪除,顯示的內容我現在想的是。
.trim
將段落設置爲固定高度,並將溢出設置爲隱藏。
只是僅供參考,我並不是說你的代碼不起作用,但它有點奇怪的使用'.filter()'。你可能想用'.each()'來代替。或者使用'.filter()'做更多的事情:'$('。moreDetails p.additionalText')。filter(function(){return $(this).text()。length> 32;})。addClass ( '修剪');' – user113716 2010-08-13 15:11:53