在ajax请求成功的方法里写click事件,实现显示隐藏功能,但结果点击一次,可能触发多次显示隐藏的切换,后采用先解绑click事件再绑定click事件的方法解决掉,ps:unbind后添加click,不要写明方法,不然还是会出现上述问题。代码如下:
$(".store-value-drop-down").each(function () { // event.stopPropagation(); $(this).unbind('click').bind('click',function(){ var elem=$(this).parent().next('.store-value-contain'); if(elem.css('display')=='none'){ elem.show(); // return ; }else if(elem.css('display')=='block'){ elem.hide(); // return ; } }); });
$(".store-value-drop-down").each(function () { $(this).unbind('click').bind('click',function () { var temp1=$(this).data("storeidd"); console.log(temp1); $(".storeIdd"+temp1).toggle(); }) });
$(".store-value-drop-down").each(function () { //ps:这种方式还是会出问题 $(this).unbind('click',function(){ var temp1=$(this).data("storeidd"); console.log(temp1); $(".storeIdd"+temp1).toggle(); }).bind('click',function () { var temp1=$(this).data("storeidd"); console.log(temp1); $(".storeIdd"+temp1).toggle(); }) });
ps:有小伙伴明白其中奥秘的可以帮忙说一下哦