js/jquery 事件绑定与取消

发布时间:2020-06-08 11:17:06 作者:though_123
来源:网络 阅读:364

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <title> New Document </title>
  <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
  <script type="text/javascript" src="js/jquery-1.8.3.js">
  </script>
  <script type="text/javascript">
 jQuery(document).ready(
  function(){
   $("#i").bind("click",function(){
    alert('jquery绑定 1!');
   
   }); 
   $("#i").bind("click",function(){
    alert('jquery绑定 2!');
   
   }); 
   
   var handler = function(){
    alert("js绑定!")
   
   };
   
   document.getElementById("i").attachEvent(" ;
   //document.getElementById("i").addEventListener("click",handler)  ;//这里绑定用click(firefox)
   
   $("#i").unbind("click");
   
   //document.getElementById("i").detachEvent("onclick",handler);//而这里绑定用onclick (IE)
   
  }
 );
  </script>
 </head>
 <body>
 <input type="button" value="点击我" id="i"/>
 </body>
</html>

要注意 : 事件的绑定和取消成对出现,比如 bind 对应unbind ,而attachEvent对应detachEvent

unbind是无法取消attachEvent绑定的东西的。

另外js绑定与jquery绑定触发执行顺序与不同浏览器有关

 

 

推荐阅读:
  1. Swift -- 函数的使用(函数作为参数、返回值、嵌套函数)
  2. 学习Swift的IOS应用的代码教程-5:让应用变的美观

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

js jquery 事件绑定 ue j

上一篇:用代码来示例MySql实现循环插入数据

下一篇:Java 趣史-差点把 Java 命名成了 Silk(丝绸)

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》