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

标签 javascript jquery twitter-bootstrap checkbox

我在 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/

相关文章:

javascript - 对象内的 svg 元素不会触发 css 动画

javascript - 带有子菜单的 Bootstrap 导航栏 - 如何删除 768 下的类 "disabled"@media width

javascript - 仅将节 ID 名称添加到数组一次

javascript - Google Pub/Sub 如何在 Pull 上设置读取超时

javascript - 当从 javascript 调用字符串时,Latex 不渲染?

jquery - 图表类别文本的自定义样式

javascript - 单击时如何不触发 Bootstrap 选项卡?

javascript - React-Native Webview 使用音频播放器可以吗?

javascript - img src 在 Firefox 和 IE 的 jQuery 脚本中没有改变

javascript - 如何从 Javascript 进行成功的 JSON 调用