禁用具有不同日期的复选框
Disable checkbox having different date
<?php
while($row = mysqli_fetch_array($result)){
?>
<tr>
<td>
<input type="checkbox"
id="<?php echo $row['invoice_id']; ?>"
name="invoice_id[]"
rel="<?php echo $row['due_date']; ?>"
value="<?php echo $row['invoice_id'];?>">
</td>
<td><?php echo $row['invoice_no']; ?></td>
<td><?php echo $row['due_date']; ?></td>
</tr>
<?php
}
?>
我的问题是如何禁用所有不等于选中第一个复选框的截止日期的复选框
例
invoice_no due_date
1 10-15-2014
2 10-15-2014
3 10-16-2014
4 10-17-2014
如果我选中invoice_no 1,invoice_no 3 和 4 将被禁用如果我取消选中invoice_no 1,则将启用所有check_box
到目前为止,我只有这个,不知道下一步该做什么,我搜索了网络,但仍然找不到如何做到这一点
$("input[type=checkbox]").change(function() {
$due_date = $(this).attr("rel");
});
TIA为您提供帮助.....
你可以试试这个:
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script>
$(document).ready(function() {
$('input[type=checkbox]').change(function(){
var chk = $(this).attr('rel');
if($(this).is(':checked'))
{
$('input[type=checkbox]').each(function(){
var chks = $(this).attr('rel');
if(chk != chks)
{
$(this).attr('disabled','true');
}
});
}
else
{
var temp ='';
$('input[type=checkbox]').each(function(){
if($(this).is(':checked'))
{
temp = $(this).attr('rel');
return false;
}
});
$('input[type=checkbox]').each(function(){
if(temp != chk)
{
$(this).removeAttr('disabled');
}
});
}
});
</script>
查看此代码。
$(document).ready(function(){
$("input[type=checkbox]").change(function() {
//alert($(this).attr("rel"));
$due_date = $(this).attr("rel");
$id = $(this).val();
var $check = false;
if($(this).is(':checked')){
$("input[type=checkbox]").each(function(){
if($(this).val()!=$id){
if($(this).attr("rel")==$due_date){
$(this).prop('disabled',false);
}else{
$(this).prop('disabled',true);
}
}
});
}else{
$("input[type=checkbox]").each(function(){
if($(this).val()!=$id & $(this).is(':checked')){
$check = true;
}
});
if(!$check){
$("input[type=checkbox]").each(function(){
$(this).prop('disabled',false);
});
}
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="checkbox"
id="1"
name="invoice_id[]"
rel="10-15-2014"
value="1">
<input type="checkbox"
id="2"
name="invoice_id[]"
rel="10-15-2014"
value="2">
<input type="checkbox"
id="3"
name="invoice_id[]"
rel="10-16-2014"
value="3">
<input type="checkbox"
id="4"
name="invoice_id[]"
rel="10-17-2014"
value="4">
这将起作用.. :)
相关文章:
- 如何在angularJS中编辑时,如果DB中的值为true,则设置复选框,如果值为false,则取消选中复选框
- 正在验证8个真/假复选框或复选框中的2个
- 为复选框javascript指定两个值
- 如何在单击复选框后调用控制器方法
- 从复选框和Selects-KnockoutJS中获取值的总和
- 选中多个具有相同名称的复选框
- 使用Jquery选择或取消选择ListView中的所有复选框
- Jquery表单验证插件-如果选中复选框,如何在提交时执行某些操作
- 使用$.ajax发布多个复选框
- 单击复选框时显示日期选择器
- 在表中搜索相同的日期,并在td中添加复选框
- 在 extjs4 中编辑时需要对齐复选框、添加多条记录并查看日期归档
- 根据 Knockout.js 中的复选框绑定将来的日期选择器最大日期
- jQuery清除日期选择器字段中的值,该值与未选中的复选框相关联
- HTML表单浏览器侧复选框和jQuery日期选择器条目复选框
- 禁用具有不同日期的复选框
- ReactJs复选框值和日期未在状态中更新
- 在jquery复选框中返回系统日期
- 完整日历:每个月的日期上的复选框
- 如何在PHP CRUD编辑操作中获取日期和复选框数据