为何这段JS在aspx里不执行了??
aaa <input type= "checkbox " name= "checkbox " value= "aaa " onclick= "check() ">
bbb <input type= "checkbox " name= "checkbox " value= "bbb " onclick= "check() ">
ccc <input type= "checkbox " name= "checkbox " value= "ccc " onclick= "check() ">
ddd <input type= "checkbox " name= "checkbox " value= "ddd " onclick= "check() ">
<input type= "text " name= "text1 " readonly>
<script language= "JavaScript ">
function check()
{
var a = document.getElementsByName( "checkbox ");
var b = document.getElementsByName( "checkbox ");
var s=0;
for (var i=0; i <a.length; i++)
//if(a[i].value!== " ") s=s+parseInt(a[i].value);
if(a[i].checked) s=s+(b[i].value);
document.form1.text1.value=s;
}
</script>
这段代码放在单独的html页面里可以执行,但放到 aspx页面里却不执行了.怎么回事????
------解决方案--------------------估计是你的checkbox是服务器端控件,生成html后name属性变了,你可以查看生成后的代码是什么
改成这样:
function check()
{
var objs = document.getElementsByTagName( "input ");
for (var i = 0; i < objs.length; i ++)
{
if(objs[i].type == "checkbox ")
{
if (objs[i].id.indexOf( "checkbox ") != -1)
{
if(objs[i].checked) s=s+(objs[i].value);
}
}
}
docume