各位大侠:在下有个script,不知道哪里出错了,请指点下!<script type="text/javascript">
function FiveSelect()
{
var i=0;
var n=0;
for(i=2;i<=16;i++)
{
var chb= document.getElementById("_3355__ctl"+i+"__ctl2_0");
if(chb.checked=="checked")
{
n=n+1;
}
}
if(n>5)
{
alert("最多只能选择五项!");
}
if(n<5)
{
alert("最少要选择五项!");
}
}
document.getElementById('processPageBtn').onclick = function(){FiveSelect();};
</script>
function FiveSelect()
{
var i=0;
var n=0;
for(i=2;i<=16;i++)
{
var chb= document.getElementById("_3355__ctl"+i+"__ctl2_0");
if(chb.checked=="checked")
{
n=n+1;
}
}
if(n>5)
{
alert("最多只能选择五项!");
}
if(n<5)
{
alert("最少要选择五项!");
}
}
document.getElementById('processPageBtn').onclick = function(){FiveSelect();};
</script>
document.getElementById('processPageBtn').onclick = function(){FiveSelect();};
不工作而是
for(i=2;i<=16;i++)
{
var chb= document.getElementById("_3355__ctl"+i+"__ctl2_0");
if(chb.checked=="checked")
{
n=n+1;
}
}不工作。请看下!
改成if(chb.checked)再试下
{
n=n+1;
}改成这样~··
<script type="text/javascript">
function FiveSelect()
{
var i=0;
var n=0;
for(i=2;i<=16;i++)
{
var chb= document.getElementById("_3355__ctl"+i+"__ctl2_0");
if(chb.checked)
{
n=n+1;
}
}
if(n>5)
{
alert("最多只能选择五项!");
}
if(n<5)
{
alert("最少要选择五项!");
}
}
window.onload=function(){
document.getElementById('processPageBtn').onclick = function(){FiveSelect();};
}
</script>
<input type="button" value="processPageBtn click" id="processPageBtn">
<input type="checkbox" id="_3355__ctl2__ctl2_0" value="">
<input type="checkbox" id="_3355__ctl3__ctl2_0" value="">
<input type="checkbox" id="_3355__ctl4__ctl2_0" value="">
<input type="checkbox" id="_3355__ctl5__ctl2_0" value="">
<input type="checkbox" id="_3355__ctl6__ctl2_0" value="">
<input type="checkbox" id="_3355__ctl7__ctl2_0" value="">
<input type="checkbox" id="_3355__ctl8__ctl2_0" value="">
<input type="checkbox" id="_3355__ctl9__ctl2_0" value="">
<input type="checkbox" id="_3355__ctl10__ctl2_0" value="">
<input type="checkbox" id="_3355__ctl11__ctl2_0" value="">
<input type="checkbox" id="_3355__ctl12__ctl2_0" value="">
<input type="checkbox" id="_3355__ctl13__ctl2_0" value="">
<input type="checkbox" id="_3355__ctl14__ctl2_0" value="">
<input type="checkbox" id="_3355__ctl15__ctl2_0" value="">
<input type="checkbox" id="_3355__ctl16__ctl2_0" value="">