我有一段文本,我希望显示截断,但单击时它会展开显示其余部分。再次点击应该截断它。使用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