<html>
<head>
<title>歌曲选择的实现</title>
<script language="javascript" type="text/javascript">
function selAll()
{
var playlist=document.getElementById("divlist");
var inputs=playlist.getElementsByTagName("input");
for(var i=0;i<inputs.length;i++){
var inp=inputs[i];
if(inp.type=="checkbox"){
inp.checked="checked";
}
}
}
function none()
{
///全不选
var playlist=document.getElementById("divlist");
var inputs=playlist.getElementsByTagName("input");
for(var i=0;i<inputs.length;i++){
var inp=inputs[i];
if(inp.type=="checkbox"){
inp.checked="";
}
}
}
///反选操作;
function f()
{
var playlist=document.getElementById("divlist");
var inputs=playlist.getElementsByTagName("input");
for(var i=0;i<inputs.length;i++){
var inp=inputs[i];
if(inp.type=="checkbox"){
// if(inp.checked==true){
// inp.checked=" ";
// }
// else{
//inp.checked="checked";
//}
inp.checked=!inp.checked;
}
}
}
</script>
</head>
<body>
<div id="divlist">
<input type="checkbox" id="p1" ><label for="p1">伤心太平洋</label>
<input type="checkbox" id="p2"><label for="p2">兄弟</label>
<input type="checkbox" id="p3"><label for="p3">有梦的人</label>
<br>
<input type="button" value="全选" οnclick="selAll();"><input type="button" οnclick="none();" value="全不选"><input type="button" value="反选" οnclick="f()">
</div>
</body>
</html>
<head>
<title>歌曲选择的实现</title>
<script language="javascript" type="text/javascript">
function selAll()
{
var playlist=document.getElementById("divlist");
var inputs=playlist.getElementsByTagName("input");
for(var i=0;i<inputs.length;i++){
var inp=inputs[i];
if(inp.type=="checkbox"){
inp.checked="checked";
}
}
}
function none()
{
///全不选
var playlist=document.getElementById("divlist");
var inputs=playlist.getElementsByTagName("input");
for(var i=0;i<inputs.length;i++){
var inp=inputs[i];
if(inp.type=="checkbox"){
inp.checked="";
}
}
}
///反选操作;
function f()
{
var playlist=document.getElementById("divlist");
var inputs=playlist.getElementsByTagName("input");
for(var i=0;i<inputs.length;i++){
var inp=inputs[i];
if(inp.type=="checkbox"){
// if(inp.checked==true){
// inp.checked=" ";
// }
// else{
//inp.checked="checked";
//}
inp.checked=!inp.checked;
}
}
}
</script>
</head>
<body>
<div id="divlist">
<input type="checkbox" id="p1" ><label for="p1">伤心太平洋</label>
<input type="checkbox" id="p2"><label for="p2">兄弟</label>
<input type="checkbox" id="p3"><label for="p3">有梦的人</label>
<br>
<input type="button" value="全选" οnclick="selAll();"><input type="button" οnclick="none();" value="全不选"><input type="button" value="反选" οnclick="f()">
</div>
</body>
</html>