首页 > 编程语言 > 详细

JavaScript属性操作

时间:2019-10-31 17:59:02      阅读:64      评论:0      收藏:0      [点我收藏+]

<!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>

JavaScript属性操作

原文:https://www.cnblogs.com/gerenboke/p/11772184.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!