2012-11-27 68 views
2

我试图在CLICK的LABEL上做一个简单的SELECT ALL复选框。JQuery Label单击并选择所有复选框问题

但是只有警报语句在点击标签时被处理... 在资产类型下的右侧,我点击了一个复选框,其中所有复选框都被选中。但有没有可能做到这一点点的标签,并没有复选框...

也有一个问题,清理按钮,这是一个JQuery元素和点击其中没有在复选框(理想情况下,必须得到提交)效果...

下面是代码:

<!DOCTYPE html> 
<html> 
<head> 
    <meta charset="utf-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
     <link rel="stylesheet" href="css/checkbox.css"/> 
     <link rel="stylesheet" href="css/jquery.mobile-1.1.1.css" /> 

    <title>Subscribe</title> 
    <script src="scripts/jquery-1.8.2.min.js"></script> 
    <script src="scripts/jquery.mobile-1.2.0.min.js"></script> 

    <script type="text/javascript"> 
     $(document).ready(function() { 
       $('#selectAllTechAreas').click(function(){ 
        alert('aaa'); 
        $('.techAreasCheckBox').attr('checked', this.checked); 
       }); // Tech Areas Select All click function 

       $('#selectAllAssetTypes').tap(function(event){ 
        /*$('.assetTypeCheckBox').attr('checked', this.checked);*/ 
         /*alert("Select All Asset Types clicked");*/ 
         $('.assetTypeCheckBox').attr('checked', this.checked); 
       }); // Asset Types Select All click function 
       $('#clearAllSelections').click(function(){ 
        /*$('.techAreasCheckBox').attr('checked', this.checked); 
        $('.assetTypeCheckBox').attr('checked', this.checked);*/ 

        // Problem with deselecting the HTML Checkbox with jQM element click 
       }); 
     }); // document 
    </script> 

    <style> 
     .divClassStyle { 
       color: black; 
       border: hidden; 
       width: 100%; 
       background-color: gray; 
       margin: 0px; 
       padding: 2px; 
       font-family: "Agfa Rotis Semisans"; 
       font-size: 14px; 
      } 
      .listStyle { 
       color: white; 
       border: hidden; 
       width: 100%; 
       background: orange; 
      } 
      .headerPadding{ 
       padding-left: 15px; 
      } 
      .footerPadding{ 
       padding-left: 15px; 
      } 
      .contentGrayBg{ 
       background: #e9e9e9; 
      } 
      .floatLeft{ 
       width: 50%; 
       float: left; 
      } 
      .floatRight{ 
       width: 50%; 
       float: right; 
      } 
      .container{ 
       overflow: hidden; 
      } 

      .case{ 

      } 
      .contentGrayBg{ 
       background: #e9e9e9; 
      } 
    </style> 

</head> 

<body> 
    <!-- ******** Header **********--> 
    <div data-role="header" style="padding-top: 0px"> 
     <table style="width: 100%; border: none;"> 
      <tr> 
       <td style="padding-left: 15px; width: 90%"> 

       </td> 
       <td style="border: 0px"> 

       </td> 
      </tr> 
      <tr> 
       <td style="padding-left: 15px;"> 

       </td> 
       <td> 

       </td> 
      </tr> 
     </table> 
    </div><!-- /header --> 

    <!-- ******** Content **********--> 
    <div data-role="content" class="contentGrayBg"> 
     <div id="categoriesTable"> 

      <div class="container"> 
        <div class="floatLeft"> 
          <table id="technologyAreas"> 
           <tr> 
            <td> 
             <fieldset id="techAreasCB" data-role="controlgroup"> 
             <legend style="font-style: bold; font-size:16px">Technology Areas:</legend> 
              <table> 
               <tr> 
                <td><input type="checkbox" data-mini="true" name="checkbox1" id="checkbox1" class="case techAreasCheckBox" /></td> 
                <td style="padding-left: 40px">SAP</td> 
               </tr> 
               <tr> 
                <td><input type="checkbox" data-mini="true" name="checkbox2" id="checkbox2" class="case techAreasCheckBox" /></td> 
                <td style="padding-left: 40px">Oracle</td> 
               </tr> 
               <tr> 
                <td></td> 
                <td >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label id="selectAllTechAreas" style="color: orange; padding-left: 10px"><b>Select All</b></label></td> 
               </tr> 
              </table>   
             </fieldset> 
            </td> 
           </tr> 
          </table> 
        </div> <!-- Div Class Float Left --> 

        <div class="floatRight"> 
          <table id="assetTypes"> 
           <tr> 
            <td> 
             <fieldset id="assetTypesCB" data-role="controlgroup"> 
              <legend style="font-style: bold; font-size:16px">Asset Types:</legend> 
               <table> 
                <tr> 
                 <td><input type="checkbox" data-mini="true" name="checkbox16" id="checkbox16" class="case assetTypeCheckBox" /></td> 
                 <td style="padding-left: 40px">Audio/Videos</td> 
                </tr> 
                <tr> 
                 <td><input type="checkbox" data-mini="true" name="checkbox17" id="checkbox17" class="case assetTypeCheckBox" /></td> 
                 <td style="padding-left: 40px">Documents</td> 
                </tr> 
                <tr> 
                  <td><input type="checkbox" id="selectAllAssetTypes"/></td> 
                  <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label style="color: orange; padding-left: 10px"><b>Select All</b></label></td> 
                 </tr> 
               </table>   
             </fieldset> 
            </td> 
           </tr> 
          </table> 
        </div> <!-- Div Class Float Right --> 

      </div> <!-- Div Class Container --> 
        <div style="padding-left: 10px; padding-right: 15px"> 
         <a href="#" id="clearAllSelections" data-role="button" data-mini="true" data-inline="true" style="background: orange; color: white; font-style: normal; text-shadow: none; width: 45%;">Clear</a> 
         <a href="#" data-role="button" data-mini="true" data-inline="true" style="background: orange; color: white; font-style: normal; text-shadow: none; width: 45%;">Submit</a>  <!-- Should'nt it be "Subscribe Now" as per given in the text desc above --> 
        </div> 
      </div> 
    </div> <!-- Content End --> 

    <!-- ******** Footer **********--> 
    <div data-role="footer"> 
     <div class="footerPadding"> 
      <label style="color: red; font-style: normal; font-size: 12px">Go to Accenture.com</label> <br/> 
      <label style="font-size: 12px;">&copy; 2012 Accenture. All Rights Reserved.</label> 
     </div> 
    </div> <!-- Content Footer --> 
</body> 
</html> 

回答

2

这似乎应该有我们的代码非常小的变化...只是试图改变$('.techAreasCheckBox').attr('checked', this.checked);$('.techAreasCheckBox').attr('checked', 'checked'); ...它适用于我:)并且也改变

$('#selectAllAssetTypes').tap(function(event){ 
    $('.assetTypeCheckBox').attr('checked', this.checked); 
    ..... 
} 

$('#selectAllAssetTypes').click(function(event){ 
    $('.assetTypeCheckBox').attr('checked', 'checked'); 
    ..... 
} 

检查演示here并请注泰德我没有做过的unselectAll复选框:)

+0

是的,这个作品... :)也....只是几分钟之前,我试图用真正的而不是'检查'取代它,它的工作...... :)谢谢:) –

+0

是啊...那是也是一个正确的解决方案...因为你已经尝试过'this.checked'属性,我只是建议这个解决方案:) –

1

你的主要问题是在代码:

$('.techAreasCheckBox').attr('checked', this.checked); 

它应该是

$('.techAreasCheckBox').attr('checked', true); 

换言之,您设置checked属性的方式。

+1

谢谢SemSem ...几分钟去我得到了我愚蠢的错误:) –

+0

没关系这是每一天开发人员的问题。 :) – SaidbakR