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

jQuery on()方法的优点及$().click方法的区别、删除select选中的元素

2018-03-01 17:53 369 查看
1.jQuery on()方法是官方推荐的绑定事件的一个方法

$(selector).on(event,childSelector,data,function,map)


例子:

$(document).on('click','.resetForm',function(){
$("#live_title").attr("value","");
$("#anchor_id").find("option:selected").removeAttr('selected');
$("#live_type").find("option:selected").removeAttr('selected');
});


用.on()方法绑定的事件不需要关心注册该事件的元素何时被添加进来,也不需要重复绑定,只要对应的元素添加进页面就可以触发时间。

2.jQuery click方法

$('.classname').click(function(){
});


用click方法绑定的元素如果是后来加入页面的就不能够触发时间。

3.删除select选中的元素

$("#anchor_id").find("option:selected").removeAttr('selected');
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐