简体   繁体   English

引导箱在表单上确认

[英]Bootbox Confirm on Form Submit

I'm trying to get a form submission dialog (bootbox) to work in my ASP.NET Razor application. 我正在尝试获取一个表单提交对话框(引导箱)以在我的ASP.NET Razor应用程序中工作。 I have this JavaScript code: 我有以下JavaScript代码:

   $(document).on("click", "#submit", function (e) {
        e.preventDefault();
        var $this = $(this);
        bootbox.confirm("Are you sure for your choice: " + $this.val() + "?", function (result) {
            if (result) {
                $this.submit();
            } else {
                console.log("user declined");
            }
        });
    });

And my button is: 我的按钮是:

  <div class="form-group">
        <div class="col-md-offset-2 col-md-10">
            <button type="submit" id ="submit" class="btn btn-default"><span class="glyphicon glyphicon-floppy-save"></span></button>
        </div>
    </div>
</div>

However it doesn't work at all. 但是,它根本不起作用。 I've imported the libraries and such and check if they're being loaded in Chrome and they are. 我已经导入了此类库,并检查它们是否正在Chrome中加载。

EDIT Having updated the code (see above). 编辑已更新代码(请参见上文)。 The Bootbox dialog now appears but the form does not submit. 现在会出现“启动箱”对话框,但该表单未提交。 If there are validation errors in the form when I click 'ok' it will notify the user. 如果单击“确定”时表单中存在验证错误,它将通知用户。 However once the errors are cleared and then they try to submit, it doesn't submit the form and nothing happens. 但是,一旦错误被清除,然后他们尝试提交,就不会提交表单,并且什么也不会发生。

Try targeting the actual ID 尝试定位实际ID

$(document).on("click", "#submit", function (e) { ...
             //          ^^ the hash is important ...

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

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