簡體   English   中英

函數預期的JavaScript錯誤

[英]Function Expected JavaScript Error

當用戶點擊“創建”按鈕並且特定字段為空或空格時,使用MVC ..,然后顯示對話框進行確認。 如果該字段具有值,則不顯示對話框,而直接轉到HttpPost控制器方法。

這是我到目前為止的內容:

CSHTML:

<div class="form-group">
    @Html.LabelFor(model => model.ATime, "ATime:", htmlAttributes: new { @class = "control-label col-md-2" })
    <div class="col-md-10">
        @Html.EditorFor(model => model.ATime, new { htmlAttributes = new { id = "AValue", @class = "form-control a-textbox", @placeholder = "xxxx.x" } })
        @Html.ValidationMessageFor(model => model.ATime, "", new { @class = "text-danger" })
    </div>
</div>

<div id="dialog" title="Basic dialog">
    <p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.
    </p>
</div>

<input type="submit" value="Create" class="btn btn-primary btnSubmitDS" />

JavaScript:

$(document).ready(function () {
    $(".btnSubmitDS").on("click", function (e) {
        var aValue = $("#AValue").val();

        alert(aValue);

        if (aValue == null || aValue.length() == 0) {
            $(function () {
                $('#dialog').dialog();
            });
        }
    });
});

CSS:

#dialog{
    display:none;
}

現在,單擊按鈕時會向用戶發出正確的值,但會在JS的if語句中引發錯誤,提示:

預期功能

我試圖在JSFiddle中重新創建它,並且警告了正確的值,但是該對話框也沒有出現,並且確實包含了jQuery庫。

任何幫助表示贊賞。

使用aValue.length而不是aValue.length()

 $('#SubmitBTN').on("click", function (e) {
    var value = $('#TextBox').val();
    if(value == null || value.length == 0){
        $(function() {
            $('#dialog').dialog();
        });
    }
  });

使用aValue.length而不是aValue.length()。 並在jquery文件之后添加jquery UI。 ''

暫無
暫無

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

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