首页 > 解决方案 > 使用 jQuery 在模态框内设置输入掩码

问题描述

仅当从下拉列表中选择了某些值时,我才需要屏蔽输入。我设法调用javascript函数表单代码,后面将调用jquery。当我显示警报时,它工作正常。当我试图屏蔽输入时(在加载模态并从下拉列表中选择值之后)我的模态消失并且我无法单击任何地方。

需要屏蔽的输入字段:

<input id="txt_debtor_phone" name="txt_debtor_phone" placeholder="Phone" class="form-control txt_debtor_phone frm_debtor_request" runat="server" />

满足条件时从后面的代码调用 JS 函数:

ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "mask_phone_number", "javascript:mask_phone_number();", true);

模态中的JS函数:

function mask_phone_number() {
            jqueryfunction("I am here");
            //alert("hello");
        }

模态中的jQuery函数:

$(document).ready(function () { 
            jqueryfunction = function (test) {
               // alert(test);
                $('input[name=txt_debtor_phone]').mask('000-000-000');
            }
});

标签: javascriptjquery

解决方案


将 .modal-backdrop 类属性更改为不显示


推荐阅读