1.我需要做一個閱讀全文..並且能收起的功能
一開始我會先執行一個方法show(),只顯示部分文字,之後點連結會顯示全部,但我收起這塊地方法不知如何運作,懇請大神幫幫忙,給個方向
相关代码
// 请把代码文本粘贴到下方(请勿用图片代替代码)
Introduction_html+="<div class='doc_formation'>"
$.each(this.board,function(){
Introduction_html+="<br><span class ='doc_title'>"+this.title+"</span><br>"
Introduction_html+="<span class='doc_connent'>"+this.content+"</span>"
});
Introduction_html+="<a class='back' href='javascript: void(0)' style='display:none' onclick=''>收起</a>"
Introduction_html+="</div>"
function show(){
$(".doc_formation").each(function(){
var text=$(this).html();
if($(this).text().length>lng){
$(this).text($(this).text().substring(0,lng));
$(this).html($(this).html()+"..."+"<a href='javascript: void(0)'> 閱讀全文</a>");
}
$(this).find("a").click(function(){
$(this).parent().html(text);
$(".back").css("display","block");
})
})
}
我希望能按下收起,變回只顯示部分文字,然後點閱讀全文又可以跑出全部,我現在遇到的錯誤是點了一個閱讀全文,按收起後,其他的閱讀全文就不能點擊了
扫了一遍代码,大概错误是:你给 阅读全文,收起绑定了事件,然后你使用了
html()
你替换了文档元素,且事件也会丢失,你需要使用事件委托来解决,望采纳!