简体   繁体   English

"无法禁用在模式外单击并关闭的功能"

[英]Can't disable the feature to click outside of modal and close

I have a bootstrap modal that I've set to open on page load, which works perfectly.我有一个引导模式,我设置为在页面加载时打开,效果很好。

However, I'm trying to disable the feature where it closes if you click outside of the modal.但是,如果您在模式之外单击,我会尝试禁用它关闭的功能。

It contains a required form that must be filled and submitted in order for the modal to close, which is something I'm working on with the submit button, but I need to first make sure the user can't close this modal any other way without filling in the form and submitting.它包含一个必需的表单,必须填写并提交才能关闭模式,这是我正在使用提交按钮进行的​​工作,但我需要首先确保用户不能以任何其他方式关闭此模式无需填写表格并提交。

Here's the current code:这是当前代码:

<script type="text/javascript"> 
$(window).on('load',function(){
    $('#my_modal').modal('show');
    $("#my_modal").modal({
        backdrop: 'static',
        keyboard: false
    });

});
</script>

Add the show property to the modal and only call once将 show 属性添加到模态并且只调用一次

<script type="text/javascript"> 
$(window).on('load',function(){
    $("#my_modal").modal({
        backdrop: 'static',
        keyboard: false,
        show: true // added property here
    });
});
</script>

I just used .add instead of .toggle inside window event which fixed the issue.我只是在窗口事件中使用 .add 而不是 .toggle 来解决问题。

function windowOnClick(event) {
  console.log(event.target)
    if (event.target == modal) {
         modal.classList.add("modal-show");
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM