一 bind方法

原型: bind(type,[data],fn)

作用:为每一个匹配的元素的特定事件绑定一个事件处理器函数

返回值:Object

参数:type(String):事件类型

   data(Object):【可选】作为event.data属性值传递给事件对象的额外数据对象

         fn(Function):绑定到每个匹配元素的事件上面的处理函数

 1 常规绑定

<input type="button" value="test" />  

<div ></div> 

 jQuery代码:

$(document).ready(function(){
		$("#button").bind(
			"click",function(){$("#test2").text("this is a test");});
	});

 2 多事件绑定

<input type="button" value="test" />  

<div ></div> 

 

 jQuery代码:

	$(document).ready(function(){
		$("#button").bind(
			"click mouseover",function(){$("#test2").text("this is a test");});
	});

 3 映射绑定

<input type="button" value="test" />  

<div ></div> 

 

jQuery代码:

	$(document).ready(function(){
		$("#button").bind(
		{
			click:function(){$("#test2").text("this is a test");},
			mouseover:function(){$("#test2").text("this is girl");}
		});
	});

4  取消默认的行为,阻止事件冒泡

 事件处理函数必须返回false

例子代码:function(){return false;}

5  可选参数data的应用

这是一个可选项,这个参数主要用来设置处理函数需要使用的参数

HTML代码同上

jQuery代码:

	$(document).ready(function(){
		function hand(event){
			alert(event.data.mm);
			}
		$("#button").bind(
			"click",{mm:"Allen"},hand
		);
	})

相关文章:

  • 2021-06-29
  • 2022-01-17
  • 2021-12-18
  • 2021-11-19
  • 2022-12-23
  • 2022-02-20
  • 2021-09-15
  • 2018-12-02
猜你喜欢
  • 2022-12-23
  • 2021-07-08
  • 2022-12-23
  • 2022-01-14
  • 2021-10-11
  • 2021-06-05
  • 2021-12-16
相关资源
相似解决方案