<script language="javascript">
<!--
var checkboxName = "c";
var maxCheckbox = 10;
var maxSelected = 3;function mycheck(ctrl) {
var num = 0;//控制当选择了三个项目时候,弹出提示
var inp = document.getElementsByTagName("INPUT");
for (i=0;i<inp.length;i++)
{
if (inp[i].type=="checkbox")
{
if (inp[i].checked == true)
num ++;
}
}
if (num > maxSelected)
{
alert("你已选择了三个!只有取消(再次点击)已选才能选其它。");
ctrl.checked = false;
}
}
//-->
</script><form name="form1" method="post" action="">
<table width="400" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><input type="checkbox" name="c1" value="300" onClick="mycheck(this)"></td>
<td>a</td>
</tr>
<tr>
<td><input type="checkbox" name="c2" value="checkbox" onClick="mycheck(this)"></td>
<td>b</td>
</tr>
<tr>
<td><input type="checkbox" name="c3" value="checkbox" onClick="mycheck(this)"></td>
<td>c</td>
</tr>
<tr>
<td><input type="checkbox" name="c4" value="checkbox" onClick="mycheck(this)"></td>
<td>d</td>
</tr>
<!--
<tr>
<td><input type="checkbox" name="c5" value="checkbox" onClick="mycheck(this)"></td>
<td>e</td>
</tr>
-->
<tr>
<td><input type="checkbox" name="c6" value="checkbox" onClick="mycheck(this)"></td>
<td>f</td>
</tr>
<tr>
<td><input type="checkbox" name="c7" value="checkbox" onClick="mycheck(this)"></td>
<td>g</td>
</tr>
<tr>
<td><input type="checkbox" name="c8" value="checkbox" onClick="mycheck(this)"></td>
<td>h</td>
</tr>
<tr>
<td><input type="checkbox" name="c9" value="checkbox" onClick="mycheck(this)"></td>
<td>i</td>
</tr>
<tr>
<td><input type="checkbox" name="c10" value="checkbox" onClick="mycheck(this)"></td>
<td>j</td>
</tr>
</table>
</form>
<!--
var checkboxName = "c";
var maxCheckbox = 10;
var maxSelected = 3;function mycheck(ctrl) {
var num = 0;//控制当选择了三个项目时候,弹出提示
var inp = document.getElementsByTagName("INPUT");
for (i=0;i<inp.length;i++)
{
if (inp[i].type=="checkbox")
{
if (inp[i].checked == true)
num ++;
}
}
if (num > maxSelected)
{
alert("你已选择了三个!只有取消(再次点击)已选才能选其它。");
ctrl.checked = false;
}
}
//-->
</script><form name="form1" method="post" action="">
<table width="400" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><input type="checkbox" name="c1" value="300" onClick="mycheck(this)"></td>
<td>a</td>
</tr>
<tr>
<td><input type="checkbox" name="c2" value="checkbox" onClick="mycheck(this)"></td>
<td>b</td>
</tr>
<tr>
<td><input type="checkbox" name="c3" value="checkbox" onClick="mycheck(this)"></td>
<td>c</td>
</tr>
<tr>
<td><input type="checkbox" name="c4" value="checkbox" onClick="mycheck(this)"></td>
<td>d</td>
</tr>
<!--
<tr>
<td><input type="checkbox" name="c5" value="checkbox" onClick="mycheck(this)"></td>
<td>e</td>
</tr>
-->
<tr>
<td><input type="checkbox" name="c6" value="checkbox" onClick="mycheck(this)"></td>
<td>f</td>
</tr>
<tr>
<td><input type="checkbox" name="c7" value="checkbox" onClick="mycheck(this)"></td>
<td>g</td>
</tr>
<tr>
<td><input type="checkbox" name="c8" value="checkbox" onClick="mycheck(this)"></td>
<td>h</td>
</tr>
<tr>
<td><input type="checkbox" name="c9" value="checkbox" onClick="mycheck(this)"></td>
<td>i</td>
</tr>
<tr>
<td><input type="checkbox" name="c10" value="checkbox" onClick="mycheck(this)"></td>
<td>j</td>
</tr>
</table>
</form>
if (nowCtrl.checked)
num++;
你取得对象的时候有问题
改成
nowCtrl = eval("document.form1."+checkboxName+i);