gpt4 book ai didi

javascript - 将确认 Bootstrap 模式/对话框添加到复选框

转载 作者:行者123 更新时间:2023-11-30 17:17:04 25 4
gpt4 key购买 nike

我在 map 中有一个表单复选框。未选中时,我希望用户获得一个 Bootstrap 确认对话框,询问“你确定要关闭开关吗?”在句柄命令之前。

代码:

command.onAdd = function (map) {
var div = L.DomUtil.create('div', 'command');
div.innerHTML = '<form><input id="command" checked="true" type="checkbox"/>switch</form>';
return div;
};
command.addTo(map);

document.getElementById("command").addEventListener("click", handleCommand, false);

function handleCommand() {

if(this.checked == true){

}
else
{

}
}

最佳答案

你可以使用bootbox.js作为一种方便的方式来做到这一点:

function handleCommand() {
var checkbox = $(this);
if (!checkbox.is(':checked')) {
bootbox.confirm("Are you sure?", function (result) {
if (result) {
// your code
} else {
checkbox.prop('checked', true);
}
});
}
}

关于javascript - 将确认 Bootstrap 模式/对话框添加到复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25912206/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com