我正在尝试在CLEL of LABEL上创建一个简单的SELECT ALL复选框。
但只有点击标签才能处理警报声明...... 在资产类型下的右侧,我点击了一个复选框,其中选中了所有复选框。但是可以通过点击标签来完成它而根本没有复选框......
Clear按钮也是一个问题,它是一个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 > <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> <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;">© 2012 Accenture. All Rights Reserved.</label>
</div>
</div> <!-- Content Footer -->
</body>
</html>
答案 0 :(得分: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并请注意我没有完成取消选择所有复选框的代码:)
答案 1 :(得分:1)
您的主要问题在于:
$('.techAreasCheckBox').attr('checked', this.checked);
应该是
$('.techAreasCheckBox').attr('checked', true);
换句话说,就是设置checked属性的方式。