簡體   English   中英

TwitterBootStrap提交按鈕仍然提交表單

[英]TwitterBootStrap Submit Button still submits the form

我有以下Bootstrap提交按鈕和onclick功能。

@Html.Bootstrap().SubmitButton().Text("Submit Final").Id("btnSubmitBottom").Style(ButtonStyle.Primary).HtmlAttributes(new { onclick = "return SubmitCheck('Submit Final')", name = "command", value = "Submit Final" }).Disabled(blnButtonsDisabled)

SubmitCheck有這個調用另一個函數的ajax代碼並返回一個文本值。 基於該值,我向用戶顯示一個確認框(true)或一個Bootbox模式(false)。

               $.ajax({
                    type: "GET",
                    url: "professionalismSubmitFinal",
                    data: { teacherID: CurrentTeacherID },
                    dataType: "text",
                    error: function (xhr, status, error) {
                    },
                    success: function (textVal) {
                        if (textVal == 'True') {
                            if (confirm("Are you sure you want to submit this as final?")) {
                                $('#IsPublic').val(true);
                                $('#IsFinal').val(true);
                                submitFormOkay = true;
                                return true;
                            }
                            else {
                                $('#IsFinal').val(false);
                                return false;
                            } //cancelled from modal
                        } else {
                            bootbox.alert("You cannot Submit until this has been Submitted as Final.");
                            return false;
                        }
                    }
                });

問題是當Ajax調用返回'False'時,bootbox警報會正確顯示,但表單也會提交。

我做錯了什么? 我以為onclick = return SubmitCheck會阻止這種行為嗎?

也許event.preventDefault(); 按鈕點擊事件將幫助您

$("#yourButton").click(function(event) {
    event.preventDefault();
});

希望我能正確理解你的問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM