[英]Select and Unselect all checkboxes
I'm not able to implement these things,In this page I want to do implement 3 things: 我无法实现这些事情,在此页面中,我想实现以下三件事:
1> By default Apple and Cat will be checked in this page. 1> 默认情况下,将在此页面中选中Apple和Cat。 2> For Startall all the features will be checked and disabled.
2> 对于Startall,将检查并禁用所有功能。 3> For Stopall, all the features will be disabled as well as default (AC) value will be disabled.*
3> 对于Stopall,将禁用所有功能以及默认 (AC)值。*
<script type="text/javascript"> //This jquery is using for on selecting the checkbox,it will assign the text field of policyName and features
$(document).ready(function() {
$('.check').click(function(){
$("#policyName").val('Start');
$("#features").val('');
$(".check").each(function(){
if($(this).prop('checked')){
$("#policyName").val($("#policyName").val() + $(this).val());
$("#features").val($("#features").val() + $(this).data('name'));
}
});
});
});
</script>
Here is my jsp page : 这是我的jsp页面:
<div align="center" id="checkboxes">
<input type="checkbox" name="startall" data-name="Startall" class="check" id="check" value="all"> All
<input type="checkbox" name="stopall" data-name="Stopall" class="check" id="check" value="stopall"> STOPall
<input type="checkbox" name="apple" data-name="Apple" class="check" id="check" value="a"> Apple
<input type="checkbox" name="ball" data-name="Ball" disabled="disabled" checked="checked" id="check" value="b"> Ball
<input type="checkbox" name="cat" data-name="Cat" class="check" id="check" value="a"> Cat
<input type="checkbox" name="dog" data-name="Dog" checked="checked" disabled="disabled" id="check" value="d"> Dog
<input type="checkbox" name="elephant" data-name="Elephant" disabled="disabled" checked="checked" id="check" value="e">
Elephant
</div>
Any Assistance....will be apprciated. 任何协助...将不胜感激。
Try this 尝试这个
ID in your HTML should be unique .. Try using different id's or classes instead.. I have written the code using the name attribute which is a slow selector.. HTML中的ID应该是唯一的 ..尝试改用其他ID或类。.我已经使用name属性(这是一个缓慢的选择器)编写了代码。
$(document).ready(function() {
$('[name="apple"], [name="cat"]').prop('checked', true);
$('[name="startall"]').on('click', function() {
var $checkboxes = $('input[type="checkbox"]').not('[name="startall"], [name="stopall"]');
if (this.checked) {
$checkboxes.prop({
checked: true,
disabled: false
});
$('#textbox').val( $(this).attr('data-name'));
}
else{
$checkboxes.prop({
checked: false
});
$('#textbox').val('');
}
});
$('[name="stopall"]').on('click', function() {
var $checkboxes = $('input[type="checkbox"]').not('[name="startall"], [name="stopall"]');
if (this.checked) {
$checkboxes.prop({
checked: false,
disabled: true
});
$('#textbox').val( $(this).attr('data-name'));
}
else{
$checkboxes.prop({
disabled: false
});
$('#textbox').val('');
}
});
}); });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.