javascript checkbox 问题 var A = document.getElementById('A');//<input type="checkbox" id="A">怎么在javascript中选中? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 A.checked = true; 试试。 <input type="checkbox" id="A" checked> 全选的话是这样:var A = document.getElementById('A');if(A.length>0){ for(i=0;i<A.length;i++) { A[i].checked=true; }}else A.checked=true; 还有你的这个复选框没有value值 我只要<input type="checkbox" id="A"> 在javascript中选中,和有没有value有什么关系? 我对javascript不怎么熟悉。。求教? 有没有value值关系到服务器端能否正确使用该复选框,但这在javascript中是不关心的 <BODY onload="iniCheckBox()"> <c:forEach var="cc" items="${tcList }"> <input type="checkbox" name="C1" value="ON" id="${cc.charge_code }" > ${cc.charge_name } </c:forEach>function iniCheckBox() { document.getElementById("A").checked=true; }页面源码: 收费项目: <input type="checkbox" name="C1" value="ON" id="A" > 开户费 <input type="checkbox" name="C1" value="ON" id="B" > 漫游费 <input type="checkbox" name="C1" value="ON" id="C" > 押金 <input type="checkbox" name="C1" value="ON" id="D" > 入网费 <input type="checkbox" name="C1" value="ON" id="E" > 选号费 <p> <input type="checkbox" id="A">不行你就把id属性改为name<input type="checkbox" name="A">for(var i =1;i<document.getElementsByName("A").length;i++){ document.getElementsByName("A")[i].checked = true;} var obj=document.getElementsByName("C1");for(var i=0;i<obj.length;i++){obj[i].checked=true;}试下 LZ 是你没有粘贴出来还是怎么 你的function 函数都没有放到<script></script>标签里面 没贴,省略...里面就一句话:document.getElementById( "A ").checked=true; 但是这句话不对,清高手帮忙....谢谢~ 你是想实现什么功能?如果是想在页面加载的时候实现某些多选框是选中的,你可以用c:if控制checked在input中的输出来达到目的。 <head> <title> New Document </title> <meta name="Generator" content="EditPlus"> <meta name="Author" content=""> <meta name="Keywords" content=""> <meta name="Description" content=""> <script> function adf(){ var a = document.getElementById("A"); a.checked = true; } </script> </head> <body onload='adf()'> <input type="checkbox" id="A"> </body></html> 页面源码: 收费项目: <input type= "checkbox " name= "C1 " value= "ON " id= "A " > 开户费 <input type= "checkbox " name= "C1 " value= "ON " id= "B " > 漫游费 <input type= "checkbox " name= "C1 " value= "ON " id= "C " > 押金 <input type= "checkbox " name= "C1 " value= "ON " id= "D " > 入网费 <input type= "checkbox " name= "C1 " value= "ON " id= "E " > 选号费 <p> 仔细看下 id后面的值多了个空格怎么回事 所以document.getElementById("A") 找不到元素 <BODY onload= "iniCheckBox() "> <c:forEach var= "cc " items= "${tcList } "> <input type= "checkbox " name= "C1 " value= "ON " id= "${cc.charge_code } " > ${cc.charge_name } </c:forEach> function iniCheckBox() { document.getElementById( "A ").checked=true; } 页面源码: 收费项目: <input type= "checkbox " name= "C1 " value= "ON " id= "A " > 开户费 <input type= "checkbox " name= "C1 " value= "ON " id= "B " > 漫游费 <input type= "checkbox " name= "C1 " value= "ON " id= "C " > 押金 <input type= "checkbox " name= "C1 " value= "ON " id= "D " > 入网费 <input type= "checkbox " name= "C1 " value= "ON " id= "E " > 选号费 <p>问题错在 <input type= "checkbox " ...type="checkbox"不能有空格另外注意把 id= "A " 和document.getElementById( "A ").checked=true; 中"A "去掉空格,就好了。我已经在浏览器上测试过了。 document.getElementById( "A ").checked=true;多加了一个空格,还要确保id是唯一的! Sigar中使用哪个方法,可以通过 进程的名字来获取 PID 这个文件在哪 struts2文件下载 页面一直等待 下面这个方法改为hibernate,有点复杂,求指导。 如何将WORD嵌入JSP页面之中???? MyEclipse 初级问题 如何编译继承自定义包的JAVA文件 java高手想做兼职的看过来 如何在读文本的时候处理tab问题? jsf文件上传 Compass + paoding中文分词的问题 小妹请教一问题
var A = document.getElementById('A');
if(A.length>0){
for(i=0;i<A.length;i++)
{
A[i].checked=true;
}
}
else A.checked=true;
<c:forEach var="cc" items="${tcList }">
<input type="checkbox" name="C1" value="ON" id="${cc.charge_code }" >
${cc.charge_name }
</c:forEach>
function iniCheckBox()
{
document.getElementById("A").checked=true;
}页面源码:
收费项目:
<input type="checkbox" name="C1" value="ON" id="A" > 开户费
<input type="checkbox" name="C1" value="ON" id="B" > 漫游费
<input type="checkbox" name="C1" value="ON" id="C" > 押金
<input type="checkbox" name="C1" value="ON" id="D" > 入网费
<input type="checkbox" name="C1" value="ON" id="E" > 选号费 <p>
不行你就把id属性改为name
<input type="checkbox" name="A">
for(var i =1;i<document.getElementsByName("A").length;i++){
document.getElementsByName("A")[i].checked = true;
}
for(var i=0;i<obj.length;i++){
obj[i].checked=true;
}
试下
你的function 函数都没有放到<script></script>标签里面
如果是想在页面加载的时候实现某些多选框是选中的,你可以用c:if控制checked在input中的输出来达到目的。
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<script>
function adf(){
var a = document.getElementById("A");
a.checked = true;
}
</script>
</head> <body onload='adf()'>
<input type="checkbox" id="A">
</body>
</html>
页面源码:
收费项目:
<input type= "checkbox " name= "C1 " value= "ON " id= "A " > 开户费
<input type= "checkbox " name= "C1 " value= "ON " id= "B " > 漫游费
<input type= "checkbox " name= "C1 " value= "ON " id= "C " > 押金
<input type= "checkbox " name= "C1 " value= "ON " id= "D " > 入网费
<input type= "checkbox " name= "C1 " value= "ON " id= "E " > 选号费 <p>
仔细看下 id后面的值多了个空格怎么回事 所以document.getElementById("A") 找不到元素
<BODY onload= "iniCheckBox() ">
<c:forEach var= "cc " items= "${tcList } ">
<input type= "checkbox " name= "C1 " value= "ON " id= "${cc.charge_code } " >
${cc.charge_name }
</c:forEach>
function iniCheckBox()
{
document.getElementById( "A ").checked=true;
} 页面源码:
收费项目:
<input type= "checkbox " name= "C1 " value= "ON " id= "A " > 开户费
<input type= "checkbox " name= "C1 " value= "ON " id= "B " > 漫游费
<input type= "checkbox " name= "C1 " value= "ON " id= "C " > 押金
<input type= "checkbox " name= "C1 " value= "ON " id= "D " > 入网费
<input type= "checkbox " name= "C1 " value= "ON " id= "E " > 选号费 <p>问题错在 <input type= "checkbox " ...
type="checkbox"不能有空格
另外注意把 id= "A " 和document.getElementById( "A ").checked=true; 中"A "去掉空格,就好了。我已经在浏览器上测试过了。