【问题标题】:MDL Modal Dialog click behind modal backgroundMDL 模态对话框点击模态背景后面
【发布时间】:2017-09-03 15:50:07
【问题描述】:

我使用 https://getmdl.io/components/#dialog-section 的 Material Design Lite 创建了一个模态对话框。但我面临的问题是对话框外的区域不可点击。

我在模式之外有一个注销按钮,我希望用户在想要注销时单击该按钮。另外,我不想隐藏模式。

$(document).ready(function() {
    var dialog = document.querySelector('#main-dialog');
    if (! dialog.showModal) {
        dialogPolyfill.registerDialog(dialog);
    }
    dialog.showModal();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<dialog class="mdl-dialog" id="main-dialog">
    <h4 class="mdl-dialog__title">Select your .xlsx file:</h4>
    <div class="mdl-dialog__content">
        <p>
            Your excel sheet must contain values in the form:<br/>
            <table border="1" style="margin:0 auto">
                <tr>
                    <td><font color="black"><b>PID No.</b></font></td>
                    <td><font color="black"><b>Student Name</b></font></td>
                </tr>
            </table>
        </p>
    </div>
    <div class="mdl-dialog__actions">
       <input id="list" type="file" required="yes" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel">
    </div>
</dialog>

如何使模态框的背景可点击?

【问题讨论】:

    标签: javascript css material-design-lite


    【解决方案1】:

    要使对话框背景可点击,请使用dialog.show(); 而不是dialog.showModal();

    $(document).ready(function() {
    var dialog = document.querySelector('#main-dialog');
        if (! dialog.showModal) {
                dialogPolyfill.registerDialog(dialog);
        }
        dialog.show();
    });
    

    example


    来自 MDL 文档:

    button.addEventListener('click', function() {
       dialog.showModal();
       /* Or dialog.show(); to show the dialog without a backdrop. */   
    });
    

    【讨论】:

    • 我在 codepen 上检查了你的代码。但是当我尝试它时,当我使用此代码时,对话框根本没有出现,尽管按钮是可点击的。
    • Fork 我的 codepen 并尝试重现问题。正如您所看到的,我使用的是您自己的代码,所以它很奇怪...可能是另一个 js/css 破坏了您的代码..您有任何控制台错误吗?它应该适合你...
    • 工作,这是我在父元素中使用的 MDL 类的一些问题。谢谢!
    猜你喜欢
    • 2019-08-12
    • 1970-01-01
    • 2023-04-10
    • 1970-01-01
    • 2019-02-24
    • 2018-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多