【问题标题】:Bootstrap Modal Instead of Javascript Alert Function引导模式而不是 Javascript 警报功能
【发布时间】:2016-03-12 12:31:04
【问题描述】:

我是 JavaScript 的学习者。我需要一个引导模式而不是 java 脚本函数中的警报。我做了一些更改,但我找不到正确的解决方案。请检查我的代码并为我提供解决方案。提前致谢。

<a id="deleteButton" onClick="delete_Vehicle()" class="alert" data-toggle="tooltip" title="Delete">
<script>
function delete_Vehicle() {
    if (confirm('Do you want to delete the selected VEHICLE?')){
        DeleteDevice();
    }
}
</script>

这是我正在研究的引导模式警报功能

$(document).on('click', '.alert', function(e) {
bootbox.confirm("Really delete this item?", function(result) {
    if(result !== true){
       e.preventDefault(); 
    }
});

});

如果单击确定按钮并确认删除,则在弹出窗口中,应执行此功能 DeleteDevice();

【问题讨论】:

  • 你的意思是这样? if(result !== true){ e.preventDefault(); } else { DeleteDevice(); }
  • 这样的? jsfiddle.net/L3ddq/1
  • Bootstrap modals 不会阻塞,因此将 e.preventDefault() 放在回调中不会像您认为的那样工作。

标签: javascript jquery twitter-bootstrap bootstrap-modal bootbox


【解决方案1】:

result 回调参数决定用户是否确认操作,所以你应该检查它是否为真,然后调用DeleteDevice()

bootbox.confirm("Really delete this item?", function(result) {
  if (result === true) {
    DeleteDevice();
  }
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多