2019独角兽企业重金招聘Python工程师标准>>>
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>全选,不全选,反选</title><script src="jquery.js" type="text/javascript"></script><script src="jquery.min.js" type="text/javascript"></script><script language="javascript" type="text/javascript">$(function() {$("#checkAll").click(function() {$('input[name="subBox"]').prop("checked",this.checked); console.log( $('input[name="subBox"]'));});});</script>
</head>
<body><div id="playList"><input type="checkbox" name='subBox' value="歌曲1" />歌曲1<br /><input type="checkbox" name='subBox' value="歌曲2" />歌曲2<br /><input type="checkbox" name='subBox' value="歌曲3" />歌曲3<br /><input type="checkbox" name='subBox' value="歌曲4" />歌曲4<br /><input type="checkbox" name='subBox' value="歌曲5" />歌曲5<br /><input type="checkbox" name='subBox' value="歌曲6" />歌曲6<input type="checkbox" value="全选" id="checkAll" /><input type="button" value="全不选" id="unSelect" /><input type="button" value="反选" id="reverse" /></div>
</body>
</html>
attributes和properties之间的差异在特定情况下是很重要。jQuery 1.6之前 ,.attr()
方法在取某些 attribute 的值时,会返回 property 的值,这就导致了结果的不一致。从 jQuery 1.6 开始, .prop()
方法 方法返回 property 的值,而.attr()
方法返回 attributes 的值。