[英]Popups for checking/unchecking a checkbox
I have prompts that produce a popup when a box is ticked and unticked. 勾选并取消勾选框时,我会提示您弹出。 There looks to be a line of redundant code, but when removed the functions no longer work.
似乎有一行冗余代码,但是当删除这些功能时,它们将不再起作用。 So maybe not so redundant:-) But the #id doesn't match to anything (currently set as CAPS to not match)
因此,也许不是那么多余:-)但是#id与任何内容都不匹配(当前设置为CAPS不匹配)
Any ideas why this is interfering? 有什么想法为什么会干扰吗?
$('#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/ http://jsfiddle.net/5nd1wj54/1/
Use classes instead ids, so now redundant code needed. 使用类代替id,因此现在需要冗余代码。 You can store informations in the
data
attribute of a HTML element. 您可以将信息存储在HTML元素的
data
属性中。 jsFiddle . jsFiddle 。
I've add a class to every checkbox what should be examined. 我在每个复选框中添加了一个应该检查的类。
$(".checkIt").on('change', function() {
if ($(this).is(':checked')) {
confirm('Do you really want to change ' + $(this).data('id') + ' to NOT RECEIVED?');
}
});
HTML 的HTML
<input type="checkbox" data-id="checkbox1" class="checkIt" />
<input type="checkbox" data-id="checkbox2" class="checkIt" />
<input type="checkbox" data-id="checkbox3" class="checkIt" />
Here is what I think you mean 这就是我的意思
$('#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?');
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.