源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

浅谈jQuery的bind和unbind事件(绑定和解绑事件)

  • 时间:2021-11-14 01:33 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:浅谈jQuery的bind和unbind事件(绑定和解绑事件)
绑定其实就是把一些常规时间绑定到页面,然后进行各种常规操作 [b]解绑就是接触绑定,绑定的事件失效[/b] 要注意,iQuery中的  .事件  如(.click())其实就是单个的绑定事件的简写(bind("click")) [b]html: [/b]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
 <title>02_事件绑定.html</title>
 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
 <meta http-equiv="description" content="this is my page">
 <meta http-equiv="content-type" content="text/html; charset=UTF-8">
 <script language="JavaScript" src="../js/jquery-1.4.2.js"></script>
 <link rel="stylesheet" type="text/css" href="./css/style.css" rel="external nofollow" />
 </head>
 <body>
   <div id="panel">
   <input type="button" id="start" value="绑定事件">
   <input type="button" id="stop" value="解绑事件">
   <h5 class="head">什么是jQuery?</h5>
   <div class="content">
 jQuery是继Prototype之后又一个优秀的JavaScript库,它是一个由 John Resig 创建于2006年1月的开源项目。jQuery凭借简洁的语法和跨平台的兼容性,极大地简化了JavaScript开发人员遍历HTML文档、操作DOM、处理事件、执行动画和开发Ajax。它独特而又优雅的代码风格改变了JavaScript程序员的设计思路和编写程序的方式。
   </div>
  </div>
 </body>
 <script language="JavaScript">
 //当鼠标单次点击h5标题时,显示答案;当鼠标双次点击h5标题时,隐藏答案
// $("h5").click(function(){
//  if($("div[class=content]").is(":hidden")){
//   $("div[class=content]").show();
//  }else{
//   $("div[class=content]").hide();
//  }
// })
 
// //动态效果
// $("#start").click(function(){
//  /*
//   * 动态绑定点击事件:绑定单个事件
//   *  bind(type,data,fn)
//   *   * type:指定要绑定的事件名称
//   *   * data:(可选)作为event.data属性值传递给事件对象的额外数据对象
//   *   * fn:回调函数,function(){}
//   */
//  $("h5").bind("click",function(){
//   if($("div[class=content]").is(":hidden")){
//    $("div[class=content]").show();
//   }else{
//    $("div[class=content]").hide();
//   }
//  });
//  
// });
// $("#stop").click(function(){
//  /*
//   * 动态解绑定点击事件
//   *  unbind(type,fn)
//   *   * type:(可选)指定要解绑的事件名称
//   *   * fn:(可选)回调函数
//   */
//  $("h5").unbind();
// });
 
// $("h5").mouseover(function(){
//  $("div[class=content]").show();
// }).mouseout(function(){
//  $("div[class=content]").hide();
// });
 
 //动态效果
 $("#start").click(function(){
  /*
   * 绑定事件:绑定多个事件
   *  * 事件名称之间,用空格隔开
   */
  $("h5").bind("mouseover mouseout",function(){
   if($("div[class=content]").is(":hidden")){
    $("div[class=content]").show();
   }else{
    $("div[class=content]").hide();
   }
  });
 });
 $("#stop").click(function(){
  /*
   * unbind(type)
   *  * 默认为空时:解绑定所有事件
   *  * 指定单个事件:解绑指定的单个事件
   *  * 指定多个事件:解绑指定的多个事件
   */
  $("h5").unbind("mouseover mouseout");
  
 });
 
 </script>
</html>
以上这篇浅谈jQuery的bind和unbind事件(绑定和解绑事件)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持编程素材网。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部