var A = document.getElementById('A');//<input type="checkbox" id="A">怎么在javascript中选中?

解决方案 »

  1.   

    A.checked = true; 试试。
      

  2.   

    <input type="checkbox" id="A" checked>
      

  3.   

    全选的话是这样:
    var A = document.getElementById('A');
    if(A.length>0){
      for(i=0;i<A.length;i++)
    {
    A[i].checked=true;
    }
    }
    else A.checked=true;
      

  4.   

    还有你的这个复选框没有value值
      

  5.   

    我只要<input type="checkbox" id="A"> 在javascript中选中,和有没有value有什么关系? 我对javascript不怎么熟悉。。求教?
      

  6.   

    有没有value值关系到服务器端能否正确使用该复选框,但这在javascript中是不关心的
      

  7.   

    <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>
      

  8.   

    <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;
    }
      

  9.   

    var obj=document.getElementsByName("C1");
    for(var i=0;i<obj.length;i++){
    obj[i].checked=true;
    }
    试下
      

  10.   

    LZ  是你没有粘贴出来还是怎么 
    你的function 函数都没有放到<script></script>标签里面
      

  11.   

    没贴,省略...里面就一句话:document.getElementById( "A ").checked=true;   但是这句话不对,清高手帮忙....谢谢~
      

  12.   

    你是想实现什么功能?
    如果是想在页面加载的时候实现某些多选框是选中的,你可以用c:if控制checked在input中的输出来达到目的。
      

  13.   

     <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>
      

  14.   


    页面源码: 
      收费项目: 
      <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") 找不到元素
      

  15.   


    <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 "去掉空格,就好了。我已经在浏览器上测试过了。
      

  16.   

    document.getElementById( "A ").checked=true;多加了一个空格,还要确保id是唯一的!