相比attr,prop是1.6.1才新出来的,两者从中文意思理解,都是获取/设置属性的方法(attributes和properties)。只是,window或
相比attr,prop是1.6.1才新出来的,两者从中文理解都是获取/设置属性的方法(attributes和properties)。只是,window或
document中使用.attr()方法在jQuery1.6之前不能正常运行,因为window和document中不能有attributes。prop应运而生了。
/*
* 全选事件,点击全选,调用此函数,选中每一个checkbox
*/
$('#checkall_file').click(function(){//全选
$("[name='filename']").prop('checked','true');
});
/*
* 全不选事件,点击全不选,调用此函数,将所有的checkbox设置成不选中
*/
$('#notchose_file').click(function(){//全不选
$("[name='filename']").removeAttr("checked");
});
/*
*反选事件,点击反选,调用此函数,将所有checkbox选中设置为不选中,不选中设置为选中
*/
$('#invertchose_file').click(function(){//反选
$("[name='filename']").each(function(){
$(this).prop('checked',!$(this).prop('checked')) ;
})
});
中使用.attr()方法在jQuery1.6之前不能正常运行,因为window和document中不能有attributes。prop应运而生了。
相比attr,prop是1.6.1才新出来的,两者从中文意思理解,都是获取/设置属性的方法(attributes和properties)。只是,window或document中使用.attr()方法在jQuery1.6之前不能正常运行,因为window和document中不能有attributes。prop应运而生了。