jquery 事件绑定

1.

//bind
.bind(events [,eventData], handler)

//on
.on(events [,selector]  [,data], handler);
//如:筛选出ul下的li给其绑定click事件;
$('ul').append('<li>js new li<li>');');
$('ul').on('click', 'li', function(){console.log('click');})    //动态添加的li会绑定事件
$('ul li').on('click', function(){console.log('click');})       //动态添加的li不会绑定事件

  

猜你喜欢

转载自www.cnblogs.com/liuyj-vv/p/9554071.html
今日推荐