控制复选框最多选择4项的代码
[ 2009-03-31 16:49:52 | 作者: admin ]
保存为网页html格式
<script language=javascript>
function test(){
var thecount;
var count1;
var i;
count1=0;
for (i=0; i<12; i++){
if (document.f1.id(i).checked==true){
count1++;
if (count1>=4){
break;
}
}
}
if (count1>=4)
{
alert("最多选择:" +count1 +"项");
for (i=0; i<12; i++){
if (document.f1.id(i).checked==false){
document.f1.id(i).disabled=true;
}
}}
else
{for (i=0; i<12; i++){
document.f1.id(i).disabled=false;
}
}
}
</script>
<body>
<br><br>
<hr>
<form name="f1">
<table border=0>
<tr bgcolor="F2FAFF">
<td width="28"><input name="id" type="checkbox" value="44642" onclick="test()"></td>
<td width="132"><A href="../musiclist/1/464/44642.htm" class="d" target=_blank title="断了的弦下载">断了的弦</A></td>
<td width="28"><input name="id" type="checkbox" value="52271" onclick="test()"></td>
<td width="132"><A href="../musiclist/4/1680/52271.htm" class="d" target=_blank title="你的微笑下载">你的微笑</A></td>
<td width="28"><input name="id" type="checkbox" value="50863" onclick="test()"></td>
<td width="132"><A href="../musiclist/2/1114/50863.htm" class="d" target=_blank title="爱你下载">爱你</A></td>
<td width="28"><input name="id" type="checkbox" value="58568" onclick="test()"></td>
<td width="132"><A href="../musiclist/1/1641/58568.htm" class="d" target=_blank title="北方的天空下下载">北方的天空下</A></td>
</tr>
<tr bgcolor="F2FAFF">
<td width="28"><input name="id" type="checkbox" value="44642" onclick="test()"></td>
<td width="132"><A href="../musiclist/1/464/44642.htm" class="d" target=_blank title="断了的弦下载">断了的弦</A></td>
<td width="28"><input name="id" type="checkbox" value="52271" onclick="test()"></td>
<td width="132"><A href="../musiclist/4/1680/52271.htm" class="d" target=_blank title="你的微笑下载">你的微笑</A></td>
<td width="28"><input name="id" type="checkbox" value="50863" onclick="test()"></td>
<td width="132"><A href="../musiclist/2/1114/50863.htm" class="d" target=_blank title="爱你下载">爱你</A></td>
<td width="28"><input name="id" type="checkbox" value="58568" onclick="test()"></td>
<td width="132"><A href="../musiclist/1/1641/58568.htm" class="d" target=_blank title="北方的天空下下载">北方的天空下</A></td>
</tr>
<tr bgcolor="F2FAFF">
<td width="28"><input name="id" type="checkbox" value="44642" onclick="test()"></td>
<td width="132"><A href="../musiclist/1/464/44642.htm" class="d" target=_blank title="断了的弦下载">断了的弦</A></td>
<td width="28"><input name="id" type="checkbox" value="52271" onclick="test()"></td>
<td width="132"><A href="../musiclist/4/1680/52271.htm" class="d" target=_blank title="你的微笑下载">你的微笑</A></td>
<td width="28"><input name="id" type="checkbox" value="50863" onclick="test()"></td>
<td width="132"><A href="../musiclist/2/1114/50863.htm" class="d" target=_blank title="爱你下载">爱你</A></td>
<td width="28"><input name="id" type="checkbox" value="58568" onclick="test()"></td>
<td width="132"><A href="../musiclist/1/1641/58568.htm" class="d" target=_blank title="北方的天空下下载">北方的天空下</A></td>
</tr>
</table>
</form>
</body>
<script language=javascript>
function test(){
var thecount;
var count1;
var i;
count1=0;
for (i=0; i<12; i++){
if (document.f1.id(i).checked==true){
count1++;
if (count1>=4){
break;
}
}
}
if (count1>=4)
{
alert("最多选择:" +count1 +"项");
for (i=0; i<12; i++){
if (document.f1.id(i).checked==false){
document.f1.id(i).disabled=true;
}
}}
else
{for (i=0; i<12; i++){
document.f1.id(i).disabled=false;
}
}
}
</script>
<body>
<br><br>
<hr>
<form name="f1">
<table border=0>
<tr bgcolor="F2FAFF">
<td width="28"><input name="id" type="checkbox" value="44642" onclick="test()"></td>
<td width="132"><A href="../musiclist/1/464/44642.htm" class="d" target=_blank title="断了的弦下载">断了的弦</A></td>
<td width="28"><input name="id" type="checkbox" value="52271" onclick="test()"></td>
<td width="132"><A href="../musiclist/4/1680/52271.htm" class="d" target=_blank title="你的微笑下载">你的微笑</A></td>
<td width="28"><input name="id" type="checkbox" value="50863" onclick="test()"></td>
<td width="132"><A href="../musiclist/2/1114/50863.htm" class="d" target=_blank title="爱你下载">爱你</A></td>
<td width="28"><input name="id" type="checkbox" value="58568" onclick="test()"></td>
<td width="132"><A href="../musiclist/1/1641/58568.htm" class="d" target=_blank title="北方的天空下下载">北方的天空下</A></td>
</tr>
<tr bgcolor="F2FAFF">
<td width="28"><input name="id" type="checkbox" value="44642" onclick="test()"></td>
<td width="132"><A href="../musiclist/1/464/44642.htm" class="d" target=_blank title="断了的弦下载">断了的弦</A></td>
<td width="28"><input name="id" type="checkbox" value="52271" onclick="test()"></td>
<td width="132"><A href="../musiclist/4/1680/52271.htm" class="d" target=_blank title="你的微笑下载">你的微笑</A></td>
<td width="28"><input name="id" type="checkbox" value="50863" onclick="test()"></td>
<td width="132"><A href="../musiclist/2/1114/50863.htm" class="d" target=_blank title="爱你下载">爱你</A></td>
<td width="28"><input name="id" type="checkbox" value="58568" onclick="test()"></td>
<td width="132"><A href="../musiclist/1/1641/58568.htm" class="d" target=_blank title="北方的天空下下载">北方的天空下</A></td>
</tr>
<tr bgcolor="F2FAFF">
<td width="28"><input name="id" type="checkbox" value="44642" onclick="test()"></td>
<td width="132"><A href="../musiclist/1/464/44642.htm" class="d" target=_blank title="断了的弦下载">断了的弦</A></td>
<td width="28"><input name="id" type="checkbox" value="52271" onclick="test()"></td>
<td width="132"><A href="../musiclist/4/1680/52271.htm" class="d" target=_blank title="你的微笑下载">你的微笑</A></td>
<td width="28"><input name="id" type="checkbox" value="50863" onclick="test()"></td>
<td width="132"><A href="../musiclist/2/1114/50863.htm" class="d" target=_blank title="爱你下载">爱你</A></td>
<td width="28"><input name="id" type="checkbox" value="58568" onclick="test()"></td>
<td width="132"><A href="../musiclist/1/1641/58568.htm" class="d" target=_blank title="北方的天空下下载">北方的天空下</A></td>
</tr>
</table>
</form>
</body>
评论Feed: http://blog.xg98.com/feed.asp?q=comment&id=1225
这篇日志没有评论。
此日志不可发表评论。