我有一段文本,我希望顯示截斷,但單擊時它會展開顯示其餘部分。再次點擊應該截斷它。使用JQuery處理切換的onclick
我試圖用onclick事件來處理這個情況如下(警告:請勿在沒有閱讀下面的內容運行下面的代碼...):
<span id='blah' onclick='showAllComment("this is a long comment to see it all", 9, true)'>this is a...</span>
<script>
function showAllComment(comment, shortCommentLen, showFullComment)
{
alert($("#blah").html());
if(showFullComment)
{
$("#blah").html(comment);
$("#blah").click(showAllComment(comment, shortCommentLen, false));
}
else
{
$("#blah").html(comment.substring(0, shortCommentLen) + "...");
$("#blah").click(showAllComment(comment, shortCommentLen, true));
}
}
</script>
,但是你會看到,它反覆自己調用,你必須結束任務瀏覽器(所以要小心運行此代碼!!!!)
任何人都可以建議爲什麼發生這種情況,以及如何解決它。
在此先感謝
短 – some 2008-12-29 13:33:37
好點,但我不認爲截斷評論實際上是一個'縮寫',它會濫用標籤的最純粹的定義我認爲,什麼是任何人都認爲,這是最純粹的? – Dan 2008-12-30 11:55:40