我在用户点击复选框时创建了弹出窗口。单击复选框后,我会弹出相关消息,供用户确认是否确实要单击复选框。选中复选框并且用户想要取消选中它时相同。如果确实要取消选中复选框,我想显示带有相关消息的弹出窗口。
只需几步即可实现
很抱歉,如果这是问题的副本。
答案 0 :(得分:1)
$('#checkbox1').change(function() {
if($(this).is(':checked')){
console.log("CCCCheckeddddddd");
if(confirm("Hello")){
//enter code here i.e mark your checkbox as checked
}
}
else
{
console.log("UNCheckeddddddd");
if(confirm("Hello")){
//enter code here i.e mark your checkbox as unhecked
}
}
});
答案 1 :(得分:1)
我通过改变我的js
的代码来解决我的问题这就是我想出来的
function CustomAlert() {
debugger;
this.render = function (dialog) {
debugger;
var winW = window.innerWidth;
var winH = window.innerHeight;
var dialogoverlay = document.getElementById('dialogoverlay');
var dialogbox = document.getElementById('dialogbox');
dialogoverlay.style.display = "block";
dialogoverlay.style.height = winH + "px";
dialogbox.style.left = (winW / 2) - (550 * .5) + "px";
dialogbox.style.top = "100px";
dialogbox.style.display = "block";
document.getElementById('dialogboxhead').innerHTML = "Acknowledge This Message";
document.getElementById('dialogboxbody').innerHTML = dialog;
document.getElementById('dialogboxfoot').innerHTML = '<button >OK</button>';
}
this.ok = function () {
debugger;
document.getElementById('dialogbox').style.display = "none";
document.getElementById('dialogoverlay').style.display = "none";
}
}
var Alert = new CustomAlert();
function CheckBoxConfirm() {
this.render = function (dialog, op, id) {
debugger;
var winW = window.innerWidth;
var winH = window.innerHeight;
var dialogoverlay = document.getElementById('dialogoverlay');
var dialogbox = document.getElementById('dialogbox');
dialogoverlay.style.display = "block";
dialogoverlay.style.height = winH + "px";
dialogbox.style.left = (winW / 2) - (550 * .5) + "px";
dialogbox.style.top = "100px";
dialogbox.style.display = "block";
if ($('#sync_payments').is(":checked"))
document.getElementById('dialogboxbody').innerHTML = 'Are you sure you want to enable all device use?';
else
document.getElementById('dialogboxbody').innerHTML = ' Are you sure you want to disable all device use?';
document.getElementById('dialogboxhead').innerHTML = "Confirm that action";
//document.getElementById('dialogboxbody').innerHTML = dialog;
document.getElementById('dialogboxfoot').innerHTML = '<button onclick="Confirm.yes(\'' + op + '\',\'' + id + '\')">Yes</button> <button onclick="Confirm.no()">Cancel</button>';
}
this.no = function () {
debugger;
document.getElementById('dialogbox').style.display = "none";
document.getElementById('dialogoverlay').style.display = "none";
if ($('#sync_payments').is(":checked")) { // checked
$("#sync_payments").attr('checked', false);
}
else {
$("#sync_payments").attr('checked', true);
}
}
this.yes = function (op, id) {
debugger;
document.getElementById('dialogbox').style.display = "none";
document.getElementById('dialogoverlay').style.display = "none";
if ($('#sync_payments').is(":checked")) { // checked
// leave as it is
}
else { // unchecked
$("#sync_payments").attr('checked', false);
}
}
}
var Confirm = new CheckBoxConfirm();
并将我的HTML复选框更改为:
<label for="sync_payments"><input type="checkbox" id="sync_payments" name="sync_payments" onclick="Confirm.render()"/> Enable for all devices </label>
我得到了我想要的输出。
答案 2 :(得分:0)
onclick="Confirm.render(id)"
上的Jay Star将此更改为此onclick="Confirm.render()"
on on onclick不要传递任何参数只需调用confirm.render()
。希望这会对你有所帮助。