码迷,mamicode.com
首页 > Web开发 > 详细

jQuery 文档翻译 .on()

时间:2015-03-19 17:52:47      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:

.on( events [, selector ] [, data ], handler )

Description: Attach an event handler function for one or more events to the selected elements.

绑定一个事件处理函数到选定元素

 

The .on() method attaches event handlers to the currently selected set of elements in the jQuery object. As of jQuery 1.7, the.on() method provides all functionality required for attaching event handlers. For help in converting from older jQuery event methods, see .bind().delegate(), and .live(). To remove events bound with .on(), see .off(). To attach an event that runs only once and then removes itself, see .one()

 

.on()方法将事件处理函数绑定到当前选定的一系列元素上。

 

Event names and namespaces

Any event names can be used for the events argument. jQuery will pass through the browser‘s standard JavaScript event types, calling the handler function when the browser generates events due to user actions such as click. In addition, the .trigger() method can trigger both standard browser event names and custom event names to call attached handlers. Event names should only contain alphanumerics, underscore, and colon chraracters.

事件名称和命名空间

events参数可以是任意事件的名称。当浏览器由于用户操作产生事件时,jQuery将调用handler函数。

 

$( "p" ).on( "click", function() {
  alert( $( this ).text() );
});

  

function myHandler( event ) {
  alert( event.data.foo );
}
$( "p" ).on( "click", { foo: "bar" }, myHandler );

 

jQuery 文档翻译 .on()

标签:

原文地址:http://www.cnblogs.com/sunhe/p/4350876.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!