jQuery属性操作

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="jquery-3.1.1.js"></script>
</head>
<body><button onclick="selectall();">全选</button>
<button onclick="cancel();">取消</button>
<button onclick="reverse();">反选</button>
<table border="1">
<tr>
<td><input type="checkbox"></td>
<td>111</td>
</tr>
<tr>
<td><input type="checkbox"></td>
<td>222</td>
</tr>
<tr>
<td><input type="checkbox"></td>
<td>333</td>
</tr>
<tr>
<td><input type="checkbox"></td>
<td>444</td>
</tr>
</table>
<script>
​
​
//li=[10,20,30,40]
//dic={name:"yuan",sex:"male"}
//$.each(dic,function(i,x){
// console.log(i,x)
// })
​
​
// $("table tr").each(function () {
// console.log($(this).html())
// })
​
​
function selectall() {
$("table :checkbox").each(function () {
$(this).prop("checked",true)
})
}
​
function cancel() {
$("table :checkbox").each(function () {
$(this).prop("checked",false);
})
}
​
function reverse() {
$("table :checkbox").each(function () {
if($(this).prop("checked")){
$(this).prop("checked",false);
}
else {
$(this).prop("checked",true);
}
​
})
}
​
​
</script>
</body>
</html>
原文地址:https://www.cnblogs.com/gerenboke/p/11772184.html