亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

javascript - When clicking the "Reply" button, will multiple pieces of data be inserted when clicking "Reply" for the second time?
過去多啦不再A夢
過去多啦不再A夢 2017-05-19 10:41:22
0
2
605

Online function demonstration address (mobile phone): http://bbs2.valueonline.cn/we...
Full project code download: http://pan.baidu.com/s/1bpDznhP

When the following button is clicked to reply for the second time, multiple pieces of data will be inserted. Can anyone please tell me why?

Main js code

<script type="text/javascript">
     var onOff=true;
//收縮二級評論
$(".btnReportNum").click(function(){
    var id=$(this).attr("data-id");
    var id2="reportBox"+id;
    if(onOff){
        $("#id2").hide();
        onOff=false;
    }
    else{
        $("#id2").show();
        onOff=true;
    }
})
//文字長度限制,收縮
var showMore='<a href="javascript:" class="activeColor btnSS" data-onOff="true">展開說明</a>';
$(".detailTxt").each(function(){
    var startTxt=$(this).html();
    var length=$(this).html().length;
    var maxNum=76;
    if(length>maxNum){
        //過濾空格
        var newT=$.trim(startTxt).substring(0,maxNum)+"...";
        $(this).html(newT);
        $(this).after(showMore);
        //點擊收縮內(nèi)容;
        $(this).next().click(function(){
            var onOff=$(this).attr("data-onOff");
            if(onOff=="true"){
                $(this).prev().html(startTxt);
                $(this).html("收起");
                $(this).attr("data-onOff","false");
            }
            else{
                $(this).prev().html(newT);
                $(this).html("展開說明");
                $(this).attr("data-onOff","true");
            }
        })
    }
})

//切換回復(fù)面板;
$(".btnCannel").click(function(){
    $(".page2").hide();
    $(".page").show();
})

//點擊后要獲取-
//主貼(一級)的ID(post_id),跟貼(二級)的ID(id),評論帖子(三級)的ID,回復(fù)用戶的user_id,回復(fù)的內(nèi)容(content)
//評論答案
var userUrl='information.html';  //登陸用戶的個人主頁鏈接
var imgAva="images/img.jpg";  //登陸用戶的頭像
var userName="tuihou";  //登陸用戶的用戶名
var floorName=10;  //一共有多個條跟帖

function showEdit(){
    $(".page2").show();
    $(".page").hide();
}

//評論一級回復(fù)
$(".btnReply1").click(function(){
    showEdit();
    $("textarea.anwerArea").focus();
    $(".btnSubmit").click(function(){
         var replyContent=$("textarea.anwerArea").val();
         var replyNum=parseInt($("#replyNum").html());
         var reply1='<p class="answerOne"> <p class="userRow"> <a href="'+userUrl+'"> <img src="'+imgAva+'" alt="" class="imgAva">'+userName+'</a> </p> <p class="pb15"> <span class="detailTxt">'+replyContent+'</span> </p> <p class="answerSmall"> <span class="mr10">'+(floorName+1)+'樓</span>剛剛 <a href="javascript:" class="btnReply2 btnReply" data-id="0">回復(fù)</a> </p> </p>';
         $("#content").append(reply1);
         $(".page2").hide();
         $(".page").show();
    })
})


//判斷是否要加包裹層;
 var box='<p class="reportBox"> <img src="images/arrowsTop.png" alt="" class="arrowsTop"> <ul class="listReply2"> </ul> </p>';
//回復(fù)二級評論
$(".btnReply2").click(function(){
    showEdit();
    var temp="temp"+$(this).attr("data-id");
    $(this).addClass(temp);
    var temp='.'+temp;
    $(".btnSubmit").click(function(){
        var onOff=$(temp).parent().next().is(".reportBox");
        if(onOff){
        }
        else{
            $(temp).parent().after(box);
        }
        //獲取要加的內(nèi)容到ul中;
        var replyContent=$("textarea.anwerArea").val();
        var reply2='<li> <h4> <a href="'+userUrl+'">'+userName+'</a></h4><p class="reportTxt2">'+replyContent+'<span class="time">剛剛</span> <a class="time btnReply3" href="javascript:">回復(fù)</a> </p> </li>';
        $(".page2").hide();
        $(".page").show();
        $(temp).parent().next().find(".listReply2").append(reply2);
    })
})

</script>
過去多啦不再A夢
過去多啦不再A夢

reply all(2)
黃舟

Unbind after running

//Comment level reply
$(".btnReply1").click(function(){

showEdit();
$("textarea.anwerArea").focus();
$(".btnSubmit").click(function(){
     var replyContent=$("textarea.anwerArea").val();
     alert(replyContent);
     var replyNum=parseInt($("#replyNum").html());
     var reply1='<p class="answerOne"> <p class="userRow"> <a href="'+userUrl+'"> <img src="'+imgAva+'" alt="" class="imgAva">'+userName+'</a> </p> <p class="pb15"> <span class="detailTxt">'+replyContent+'</span> </p> <p class="answerSmall"> <span class="mr10">'+(floorName+1)+'樓</span>剛剛 <a href="javascript:" class="btnReply2 btnReply" data-id="0">回復(fù)</a> </p> </p>';
     $("#content").append(reply1);
     $(".page2").hide();
     $(".page").show();
     $(".btnSubmit").unbind();//這里要解綁,否則會在第二次執(zhí)行兩次的
})

})

小葫蘆

I didn’t read it carefully, I suggest you register $(".btnSubmit").click(function(){}放到外邊來,否則你每次點擊.btnReply1都會為.btnSubmita click callback first...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template