全選,全不選,反選 案例
阿新 • • 發佈:2019-01-27
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
<html xmlns="http://www.w3.org/1999/xhtml"> |
<head> |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
<title>全選,全不選,反選</title> |
<script
src |
<script language="javascript" type="text/javascript"> |
$(function () { |
$("#selectAll").click(function () {//全選 |
$("#playList :checkbox").attr("checked", true); |
}); |
$("#unSelect").click(function () {//全不選 |
$("#playList :checkbox").attr("checked", false);
|
}); |
$("#reverse").click(function () {//反選 |
$("#playList :checkbox").each(function () { |
$(this).attr("checked", !$(this).attr("checked")); |
}); |
}); |
}); |
</script> |
</head> |
<body> |
<div id="playList"> |
<input type="checkbox" value="歌曲1" />歌曲1<br /> |
<input
type |
<input type="checkbox" value="歌曲3" />歌曲3<br /> |
<input type="checkbox" value="歌曲4" />歌曲4<br /> |
<input type="checkbox" value="歌曲5" />歌曲5<br /> |
<input type="checkbox" value="歌曲6" />歌曲6 |
</div> |
<input type="button" value="全選" id="selectAll" /> |
<input type="button" value="全不選" id="unSelect" /> |
<input type="button" value="反選" id="reverse" /> |
</body> |
</html> |