您的位置:首页 > Web前端 > JQuery

jQuery 文档翻译 .on()

2015-03-19 16:41 274 查看

.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 );
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: