zoukankan      html  css  js  c++  java
  • jquery笔记5——jquery中事件绑定方式

    jquery中事件绑定方式

    一.JavaScript中事件绑定方式:

    1.嵌入式绑定:<input type="button" onclick="fun1()">

       缺点:一次只能为一个标签绑定监听事件

    2.基于dom对象绑定方式:

    var array = document.getElementsByName("ck");

    for(var i=0;i<array.length;i++){

          var domobj = array[i];

          domobj.onclick = fun1();

    }

           缺点:需要开发人员自行遍历数组,来绑定监听事件

    二.jQuery中事件绑定方式:


    1.$obj.jquery监听事件函数(处理函数)

      【例子】:
              $(":button").click(fun1);
              为页面中所有的button绑定onclick以及对应处理函数fun1();

      【jQuery监听事件函数】:

    html监听事件名称 jQuery监听事件函数

    onclick $obj.click(fun1);

    onchange $obj.change(fun1);

    onmouseover $obj.mouseover(fun1);

        //  jquery监听事件函数名字就是[jquery监听事件函数]去掉[on]

    2.$obj.bind("jquery监听事件函数名",处理函数):以这种方式绑定监听事件,可以解除的

    $obj.unbind():将所有监听事件从dom对象身上移除

    $obj.unbind("jquery监听事件函数名",处理函数):将指定监听事件从dom对象身上移除

  • 相关阅读:
    【loj6179】Pyh的求和
    【bzoj4036】按位或
    【CF472G】Design Tutorial: Increase the Constraints
    【bzoj4811】由乃的OJ
    双马尾机器人(???)
    【codechef】Children Trips
    【bzoj3796】Mushroom追妹纸
    【bzoj4571】美味
    前夕
    【bzoj3589】动态树
  • 原文地址:https://www.cnblogs.com/wwww2/p/12129968.html
Copyright © 2011-2022 走看看