jQuery绑定事件

在jQuery中,可以使用bind()方法进行事件的绑定。bind()功能是为每个选择元素的事件绑定处理函数,其语法格式如下所示:

bind(type,[data],fn)

其中参数type为一个或多个类型的字符串,如‘click’或‘change’,也可以自定义类型;
参数data是作为event.data属性值传递给事件处理对象的额外数据对象。
参数fn是绑定到每个选择元素的事件中的处理函数。

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
 3 <head>
 4 <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
 5 <title>bind方法绑定事件</title>
 6 <style>
 7     .btn{border: solid 1px #666;padding: 2px;width: 50px;}
 8 </style>
 9 <script src="jquery.js"></script>
10 <script>
11     $(function(){
12         $("#btnBind").bind("click",function(){  //绑定多个事件可以用空格隔开,例如:$("#btnBind").bind("click mouseout").function(){
13             $(this).attr("disabled","disabled");    //按钮不可用
14         })
15     })
16 </script>
17 </head>
18 <body>
19     <h3>功能描述</h3>
20     <p>在页面中,设置一个按钮,通过bind方法给按钮绑定一个click事件,在该事件中。</p>
21     <p>将自身的是否可用属性设置成false,即单机按钮后就不可使用。</p>
22     <input type="button" value="Button" id="btnBind" class="btn" />
23 </body>
24 </html>

结果如下图所示:

高否?富否?帅否? 否? 滚去学习!
原文地址:https://www.cnblogs.com/baixc/p/3390792.html