gpt4 book ai didi

JQuery 标签单击并选择所有复选框问题

转载 作者:行者123 更新时间:2023-11-27 22:36:16 25 4
gpt4 key购买 nike

我正在尝试制作一个简单的 SELECT ALL Check Box on CLICK of LABEL。

但是只有警告语句在点击标签时被处理...在 Assets 类型下的右侧,我放置了一个复选框,单击该复选框选中所有复选框。但是有没有可能通过点击标签来完成它而根本没有复选框......

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

最佳答案

看来你的代码应该有一个非常小的变化......只是尝试将 $('.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 复选框的代码 :)

关于JQuery 标签单击并选择所有复选框问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13584698/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com