zoukankan      html  css  js  c++  java
  • jquery

    举个例子:

    html页面

    <div><button type="button" class="test">测试</button></div>
    

    js页面

    方法1:
    $('.test').click(function(){
        alert('test');
    })
    
    方法2:
    $('div').on('click','.test',function(){
        alert('test');
    })
    

    上面两个方法表面上的效果是一样,但是实际上方法2是有动态绑定事件的功能。

    例如一个动态添加的元素,如果这个元素带有test类选择器,用方法1点击该元素是没有任何反应的,用方法2点击元素是会触发事件的。

  • 相关阅读:
    GPO
    GPO
    GPO
    Active Directory
    Active Directory
    Ethical Hacking
    Tree and Queries CodeForces
    数颜色 HYSBZ
    Powerful array CodeForces
    Group HDU
  • 原文地址:https://www.cnblogs.com/shifu204/p/6840062.html
Copyright © 2011-2022 走看看