大家好,我希望你能帮助我解决我的问题,我正在我的销售类别中构建一个 CRUD。
场景是:
如果用户将鼠标悬停在特定的行,它的评论和评论框会出现在下方。使用 jquery fadeIn()
并且用户可以在该特定行中输入他/她的评论。
我的问题是,如果我不小心将鼠标悬停在它指向其他评论的位置。因此,我为此创建了一个计时器,如果用户将鼠标悬停在该行中超过 3 秒,则无论我悬停多少行,都会出现该行的评论。
$(函数(){
var counter = 0; var myInterval = null; $(".hover_comment").hover(function(e){ //this is the first hover with an ID counter = 0; myInterval = setInterval(function(){ ++counter; console.log(counter); }, 1000); var salesid = $(this).find('span').text(); //SET IT TO VARIABLE $(".comment_boxes").hide(); setTimeout(function(){$(".comment_box_"+salesid).fadeIn()}); $('#txt_id').val(salesid); //SHOW THE COMMENT FORM $(this).find(".tempid").val(); $("#comment_add") .show(); },function(e){ //HERE'S THE FUNCTION WHEN I MOUSEOUT //CALL AGAIN var salesid = $(this).find('span').text(); $(".comment_boxes").hide(); setTimeout(function(){$(".comment_box_"+salesid).fadeIn()}); $('#txt_id').val(salesid); $(this).find(".tempid").val(); $("#comment_add") .show(); clearInterval(myInterval); if(counter > 3){ //IF TIMER REACHED GREATER THAN TO 3 SECONDS THE ID SHOULD BE PLACE IN A VARIABLE AND DISPLAY ITS CONTENTS //alert(salesid); var thisid = salesid; $(".comment_boxes").hide(); setTimeout(function(){$(".comment_box_"+thisid).fadeIn()}); $('#txt_id').val(salesid); $(this).find(".tempid").val(); $("#comment_add") .show(); }else{ //IF NOT CONTINUE TO HOVER } });
});
这是我的代码,希望你能帮助我。