忽略复选框,即禁用

问题描述:

我这里有一个代码,当你点击全部链接它将检查所有的复选框,当它将取消选中所有的复选框。忽略复选框,即禁用

但是我有一个PHP条件,当$pta_fee == $pta_fee_trans的复选框会被禁用,但是当我点击全部链接时,禁用复选框似乎被检查。

如果我检查了全部链接,我该如何忽略禁用复选框?

<div class="sub_profile right"> 
<p class="sub_content_text" style='margin-left: 25px;'> 
    <a href="javascript:selectToggle(true, 'drawing');" id="show">All</a> | <a href="javascript:selectToggle(false, 'drawing');" id="hide">None</a> 
    MISCELLANEOUS FEES: 
</p> 
<?php 
    if($pta_fee == $pta_fee_trans) 
    { 
?> 
<p class="sub_content_text" style='margin-left: 30px;'> 
    <input type='checkbox' value="<?php echo $pta_fee; ?>" disabled> 
    PTA Fee : &#8369; <?php echo $pta_fee; ?></p> 
<?php 
    } 
    else 
    { 
?> 
<p class="sub_content_text" style='margin-left: 30px;'> 
    <input type='checkbox' name='draw[]' value="<?php echo $pta_fee; ?>" id="required-checkbox1" onClick="CheckIfChecked(this.id)"> 
    PTA Fee : &#8369; <?php echo $pta_fee; ?></p> 
<?php 
    } 
    if($maintenance_fee == $maintenance_fee_trans) 
    { 
?> 
<p class="sub_content_text" style='margin-left: 30px;'> 
    <input type='checkbox' value="<?php echo $maintenance_fee; ?>" disabled> 
    Maintenance Fee : &#8369; <?php echo $maintenance_fee; ?></p> 
<?php 
    } 
    else 
    { 
?> 
<p class="sub_content_text" style='margin-left: 30px;'> 
    <input type='checkbox' name='draw[]' value="<?php echo $maintenance_fee; ?>" id="required-checkbox2" onClick="CheckIfChecked(this.id)"> 
    Maintenance Fee : &#8369; <?php echo $maintenance_fee; ?></p> 
<?php 
    } 
    if($id_school == $id_school_trans) 
    { 
?> 
<p class="sub_content_text" style='margin-left: 30px;'> 
    <input type='checkbox' value="<?php echo $id_school; ?>" disabled> 
    School ID : &#8369; <?php echo $id_school; ?></p> 
<?php 
    } 
    else 
    { 
?> 
<p class="sub_content_text" style='margin-left: 30px;'> 
    <input type='checkbox' name='draw[]' value="<?php echo $id_school; ?>" id="required-checkbox3" onClick="CheckIfChecked(this.id)"> 
    School ID : &#8369; <?php echo $id_school; ?></p> 
<?php 
    } 
    if($electricity == $electricity_trans) 
    { 
?> 
<p class="sub_content_text" style='margin-left: 30px;'> 
    <input type='checkbox' value="<?php echo $electricity; ?>" disabled> 
    Electricity : &#8369; <?php echo $electricity; ?></p> 
<?php 
    } 
    else 
    { 
?> 
<p class="sub_content_text" style='margin-left: 30px;'> 
    <input type='checkbox' name='draw[]' value="<?php echo $electricity; ?>" id="required-checkbox4" onClick="CheckIfChecked(this.id)"> 
    Electricity : &#8369; <?php echo $electricity; ?></p> 
<?php 
    } 
?> 
<div id="sub_profile_cont"> 
    <div class="sub_profile left"> 
     <p class="block_cont left"> 
      <div id = "submit-button-container" style="display:none;"> 
       <input class="action_btn" type="submit" name="submit" id="pay_btn" value="COMPUTE" onClick="setUpdateAction();"/> 
      </div> 
      <b style="display: none";><input class="action_btn" type="submit" name="submit" id="pay_btn" value="COMPUTE" onClick="setUpdateAction();"/></b> 
     </p> 
    </div> 
</div> 
</div> 

--Here是用于检查所有复选框的JavaScript代码:

<script> 
function selectToggle(toggle, form) { 
    var myForm = document.forms[form]; 
    for(var i=0; i < myForm.length; i++) { 
    if(toggle) { 
     myForm.elements[i].checked = "checked"; 
    } 
    else { 
     myForm.elements[i].checked = ""; 
     } 
    } 
} 

+0

你可以有一个隐藏字段与布尔值'$ pta_fee == $ pta_fee_trans',然后在javascript检查中使用该隐藏字段值。 – Garry

试试这个:

<script> 
function selectToggle(toggle, form) { 
    var myForm = document.forms[form]; 
    for(var i=0; i < myForm.length; i++){ 
     if(myForm.elements[i].disabled != true){ 
      if(toggle){ 
       myForm.elements[i].checked = "checked"; 
      } 
      else{ 
       myForm.elements[i].checked = ""; 
      } 
     } 
    } 
} 
+0

感谢您的代码工作。 –

+0

没问题。如果有效,请将其标记为答案。 – Christian