龍巖易富通網(wǎng)絡(luò)科技有限公司

龍巖小程序開發(fā),龍巖分銷系統(tǒng)

jQuery(5)--實現(xiàn)checkbox的全選,反選,全不選功能

2015.09.10 | 1459閱讀 | 0條評論 | javascript

頁面如下:




<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<title>demo04.html</title>


<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">

<meta http-equiv="description" content="this is my page">

<meta http-equiv="content-type" content="text/html; charset=UTF-8">


<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->

<script type="text/javascript" src="../js/jquery-1.9.1.js"></script>


<script type="text/javascript">

$(document).ready(function(){


$("#ckbAll").click(function(){

$("input[name='fav']").attr("checked",true);

});


$("#ckbno").click(function(){

$("input[name='fav']").attr("checked",false);

});


$("#ckbrec").click(function(){


$("input[name='fav']").each(function(){

// $(this).attr("checked",!$(this).attr("checked"));

this.checked=!this.checked;//用的是Dom的屬性

});


});

});

</script>

</head>


<body>

<div>

<input type="checkbox" name="fav" value="看書1" checked="checked"/>看書1

<input type="checkbox" name="fav" value="看書2" checked="checked"/>看書2

<input type="checkbox" name="fav" value="看書3" checked="checked"/>看書3

<input type="checkbox" name="fav" value="看書4" checked="checked"/>看書4

</div>


<div>

<input type="button" id="ckbAll" value="全選"/><br/><br/>

<input type="button" id="ckbno" value="全不選"/><br/><br/>

<input type="button" id="ckbrec" value="反選"/><br/>

</div>

</body>

</html>


贊 (

發(fā)表評論