zoukankan      html  css  js  c++  java
  • 一次点击触发多次事件问题

    在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:有小伙伴明白其中奥秘的可以帮忙说一下哦

    宝剑锋从磨砺出,梅花香自苦寒来。
  • 相关阅读:
    DataGridView
    View Designer
    错题集
    MetalKit_1
    倍道而行:选择排序
    ARKit_3_任意门
    ARKit__2_尺子项目
    关于scrollview的无限滚动效果实现
    tableview折叠动效
    NSURLSession的简单使用
  • 原文地址:https://www.cnblogs.com/haimengqingyuan/p/8029500.html
Copyright © 2011-2022 走看看