选中/取消选中复选框的弹出窗口

Popups for checking/unchecking a checkbox

本文关键字:窗口 复选框 取消 选中      更新时间:2023-09-26

我有提示,当一个框被打勾和未打勾时产生一个弹出框。看起来有一行多余的代码,但是当删除这些函数时就不再工作了。所以也许不是那么多余:-)但是#id不匹配任何东西(目前设置为CAPS不匹配)

知道为什么这是干扰吗?

$('#checkbox').click(function() {
  if ($("#checkbox").is(':checked')) {
    if (confirm('Are you sure you want to CONFIRM the order?')) {
      $('#CHECKBOX').click();
    }
  }
});
$("#checkbox").on('change', function() {
  this.checked = !this.checked ? !confirm('Do you really want to change this to NOT RECEIVED?') : true;
});
http://jsfiddle.net/5nd1wj54/1/

我明白你的意思了

$('#checkbox').click(function() {
  if (this.checked) {
    this.checked = confirm('Are you sure you want to CONFIRM the order?')); 
  }    
  else {
    this.checked = !confirm('Do you really want to change this to NOT RECEIVED?'); 
  }  
});

使用类代替id,所以现在需要冗余代码。可以将信息存储在HTML元素的data属性中。jsFiddle .

我已经给每个需要检查的复选框添加了一个类。

$(".checkIt").on('change', function() {
  if ($(this).is(':checked')) {
    confirm('Do you really want to change ' + $(this).data('id') + ' to NOT RECEIVED?');
  }
});