2010-06-19 43 views
1
function checkAll(custId){ 
     var id; 
     if(document.getElementById(custId).checked == true){ 
     <%for (CustomerGroup custGroup : customerGroupList) {%> 

      if(custId==<%=custGroup.getCustomerGroupId()%>){ 
       <%List<Account> list = accountDelegate 
        .findAccountEntityByGroupId(custGroup 
          .getCustomerGroupId()); 
      for (Account account : list) {%> 
         id=<%=account.getAccountId()%> 
         document.getElementById(id).checked=true; 
       <%}%> 
      } 
    <%}%> 
    }else { 
     <%for (CustomerGroup custGroup : customerGroupList) {%> 

      if(custId==<%=custGroup.getCustomerGroupId()%>){ 
      <%List<Account> list2 = accountDelegate 
        .findAccountEntityByGroupId(custGroup 
          .getCustomerGroupId()); 
      for (Account account : list2) {%> 
         id=<%=account.getAccountId()%> 
         document.getElementById(id).checked=false; 
      <%}%> 
    } 
    <%}%> 
} 
} 

在這裏,我已經通過了CUSTID作爲checkbox.Problem的ID這裏,如果(的document.getElementById(CUSTID).checked ==真怎麼知道天氣複選框選中或不使用JavaScript

每次這。?。條件將評估爲false,從而控制進上的其他部分 所以,我怎麼能知道閹複選框cheched或不

回答

3

checked屬性是你需要使用驗證什麼,如果一個複選框被選中:

<html> 
<head> 
    <title>Test</title> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <script type="text/javascript"> 
    window.onload = function() { 
     if (document.getElementById('test').checked) { 
      alert('the checkbox is checked'); 
     } 
    }; 
    </script> 
</head> 
<body> 

<input id="test" name="test" type="checkbox" checked="checked" /> 

</body> 
</html> 
2
<script language="javascript"><br> 
var test=document.getElementById('test');<br> 

if (test.checked == 1){<br> 
      alert("yes,Checked") ;<br> 
}<br> 
else<br> 
{ 
<br> 
alert("No,Please Check.")<br> 
}<br> 
</script> 

code by www.neonbrains.com

+0

沒有這個答案提供哪些額外的信息是不是已經在對方的回答給定的?另外,在這種情況下進行隱式類型轉換('test.checked == 1')真的讓人困惑。 – 2013-04-11 12:02:51

相關問題