jQuery学习笔记之.bind()
本文目标
1 了解.bind()
的几种调用方式
2 熟悉各参数含义及其格式
3 熟悉在事件处理函数中如何引用触发事件的元素
学习资料
官方描述文档: http://api.jquery.com/bind/#bind-events/
中文描述文档: http://www.css88.com/jqapi-1.9/bind/
建议: 如果时间充裕还是看官方文档
官方描述
Attach a handler to an event for the elements
把一个处理过程放在指定元素的事件上(通俗讲就是为元素绑定事件处理过程)
三种使用方式
1、.bind( eventType [, eventData ], handler )
version added: 1.0
2、.bind( eventType [, eventData ] [, preventBubble ] )
version added: 1.4.3
3、.bind( events )
version added: 1.4
eventType
Type: String
A string containing one or more DOM event types, such as “click” or “submit,” or custom event names.
参数:eventType
参数类型: String
参数说明: 参数eventType
的值是包含一个或多个文档事件类型的字符串(如”click” or “submit”),也可以是自定义的事件名称.
eventData
Type: Anything
An object containing data that will be passed to the event handlerData
参数:eventData
参数类型:Anything
参数说明:参数eventData
的值是包含将要传递给事件处理的数据对象
例如:{‘age’:10,’name’:’userName’}
handler
Type: Function( Event eventObject )
A function to execute each time the event is triggered.
参数:handler
参数类型:Function
参数说明:此处为事件每次被触发时都会执行的函数
preventBubble
Type: Boolean
Setting the third argument to false will attach a function that prevents the default action from occurring and stops the event from bubbling. The default is true.
参数:preventBubble
参数类型:Boolean
参数说明:设置这个参数为false
将附加一个阻止默认行为发生和停止事件冒泡的函数。这个参数的默认值为true
e