$(".class1").on("click",".class2",function(){
alert('提示');
});

上面代码,怎么搞都执行两次,本身对js也是半懂不懂的

查了一下资料,说法很多

主要说法集中在多次绑定和冒泡(什么意思我还没搞懂)

改法主要是说要 增加

off('click') , off('click','.class1 .class2') , unbind('.class1') , unbind('.class1 .class2')

等等,结果改完,毛线用也没有

最后找到个说在事件结束后,直接给来个“return false;”不就完事了吗!
$(".class1").on("click",".class2",function(){
alert('提示');
return false;
});

测试一下,还真搞定了

 

jQuery on 绑定的事件 执行两次的更多相关文章

  1. (转载)js(jquery)的on绑定点击事件执行两次的解决办法

    js(jquery)的on绑定点击事件执行两次的解决办法—不是事件绑定而是事件冒泡 遇到的问题:jquery中用.on()给页面中新加的元素添加点击事件时,点击事件源,绑定的事件执行两次,这里的ale ...

  2. JS: javascript 点击事件执行两次js问题 ,解决jquery绑定click事件出现点击一次执行两次问题

    javascript 点击事件执行两次js问题 在JQuery中存在unbind()方法,先解绑再添加点击事件,解决方案为: $(".m-layout-setting").unbi ...

  3. 关于jquery绑定事件执行两次

    经常会出现jquery绑定事件执行两次的情况,如: $("a[tag=slide]").click(function () { alert(1); $(this).parent() ...

  4. Jquery 事件执行两次

    js(jquery)的on绑定点击事件执行两次的解决办法—不是事件绑定而是事件冒泡 阻止冒泡的方法并不止 return false 这一种,还有event.stopPropagation(),这两种方 ...

  5. jquery ajax 中各个事件执行顺序

    jquery ajax 中各个事件执行顺序如下: 1.ajaxStart(全局事件) 2.beforeSend 3.ajaxSend(全局事件) 4.success 5.ajaxSuccess(全局事 ...

  6. WPF TreeView 选择事件执行两次,获取TreeView的父节点的解决方法

    1.TreeView选择事件执行两次 Very often, we need to execute some code in SelectedItemChanged depending on the ...

  7. jquery批量绑定click事件

    jquery批量绑定click事件: var selects = $(".public_select dd ul li"); debugger; /*$(".public ...

  8. 解决jquery click事件执行两次

    js 解决办法 event.preventDefault() :阻止默认行为,可以用 event.isDefaultPrevented() 来确定preventDefault是否被调用过了 event ...

  9. jquery ajax中各个事件执行顺序如下

    $(function(){ setTimeout(function(){ $.ajax({ url:'/php/selectStudent.php', }); },0); $(document).aj ...

随机推荐

  1. ruby 模块 respond_to

    def hi puts 'hi friend' end module Amodule def self.hello puts 'hello friend' end end def rsp(txt) p ...

  2. Xhemj的Minecraft皮肤信息

    xhemj Minecraft Profile UUID:086e0354-fbb6-446b-83d4-60bdf449ad4e UUID:086e0354fbb6446b83d460bdf449a ...

  3. 使用luabind绑定box2d的lua接口

    最近在使用luabind绑定box2d的lua接口,发现不少问题.写在这里与大家分享. 1. body,fixture,joint的userdata.box2d的userdata的数据类型是void* ...

  4. 创建dynamics CRM client-side (七) - 用JS 来控制Auto-Save

    在我们的system setting里面, 我们可以设置打开/关闭 auto save的功能. 我们可以用js来控制auto-save this.formOnSave = function (exec ...

  5. ajax--->http头信息的content-type是application/x-www-form-urlencoded或application/json区别

    ajax请求时http头信息的content-type是application/x-www-form-urlencoded或application/json区别 content-type请求头是干嘛的 ...

  6. Web自动化测试项目(三)用例的组织与运行

    一.Unittest用例组织 在test_case目录下创建test*.py,组织测试用例 ├── test_case │   ├── __init__.py │   └── test_login.p ...

  7. Tornadofx学习笔记(2)——FxRecyclerView控件的打造

    Tornadofx是基于javafx的一个kotlin框架,用来写些电脑版的小程序 基于Scroll Pane控件,仿造Android中的RecyclerView,实现的一款tornadofx的控件 ...

  8. MySQL 锁的小结

    摘自:https://www.cnblogs.com/protected/p/6526857.html 关于数据库的各种锁的总结: 1.共享锁(又称读锁).排它锁(又称写锁): InnoDB引擎的锁机 ...

  9. 整合dubbo的依赖

    <!-- 版本信息 --> <properties> <dubbo.version>2.7.3</dubbo.version> <maven-ja ...

  10. Hadoop-3.1.2安装步骤

    Hadoop-3.1.2 安装步骤 第一步  准备 服务器配置 1.  在VMware中安装把Centos7安装成功后,需要把界面设置为命令行启动,因为默认的启动方式是图形界面启动 systemctl ...