🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
事件之三个绑定事件函数 #### [.live(events \[,data\],handler)](https://api.jquery.com/live/#live-events-data-handler)   弃用:[1.7](https://api.jquery.com/category/version/1.7/),删除:[1.9](https://api.jquery.com/category/version/1.9/) ~~~ $( "a" ).live( "click",function( event ) { event.preventDefault(); }); $( "a" ).live( "click",{name:'dash'}, function( event ) { event.data.name }); $( "p" ).live({ click: function() { $( this ).after( "<p>Another paragraph!</p>" ); }, mouseover: function() { $( this ).addClass( "over" ); }, mouseout: function() { $( this ).removeClass( "over" ); } }); ~~~ #### [.bind(eventType \[,eventData\],handler)](https://api.jquery.com/bind/#bind-eventType-eventData-handler)    弃用:[3.0](https://api.jquery.com/category/version/3.0/) ~~~ $( "#foo" ).bind( "click mouseenter mouseleave", function() { $( this ).toggleClass( "entered" ); }); $( "#foo" ).bind( "click", {name:'tom'}, function() { $( this ).toggleClass( "entered" ); }); $( "#foo" ).bind({ click: function() { // Do something on click }, mouseenter: function() { // Do something on mouseenter } }); ~~~ #### [.on( events \[, selector \] \[, data \], handler )](https://api.jquery.com/on/#on-events-selector-data-handler)    1.7可用 ~~~ on: function( types(event), selector, data, fn ) { return on( this, types(event), selector, data, fn ); }, ~~~ on 示例 ~~~ $( "#dataTable tbody tr" ).on( "click", function() { console.log( $( this ).text() ); }); $( "#dataTable tbody" ).on( "click", "tr", function() { console.log( $( this ).text() ); }); $( "p" ).on( "click", { foo: "bar" }, function(event){ alert( event.data.foo ); }); $( "#dataTable tbody" ).on( "click", "tr", { foo: "bar" }, function(event){ alert( event.data.foo ); }); $( "p" ).on({ click: function() { }, mouseover: function() { }, mouseout: function() { } }); ~~~