Jquery点击打开模式返回“;undefined不是函数”;

Jquery click to open modal returns " undefined is not a function"

本文关键字:undefined 函数 返回 模式 Jquery      更新时间:2023-09-26

我试图用鼠标点击打开一个模态,但似乎根本无法让它工作。这是我的代码

<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/jquery-ui-1.10.4.custom.min.js"></script>
<script type="text/javascript">
    $("#Attack1Id").click(function () {
        var location = $.find("#dialog");
        $(location).dialog({
            title: "Dialog box",
            height: 300,
            modal: true,
            open: function (event, ui) {
                $(this).load("@Url.Action("FileTables", "Card")");
            },
            on: ('click', '.table a', function () {
                alert($(this).closest('tr').find('td:first').text())
            })
        })
    });
</script> 

"对话框"似乎是未定义的函数,但我还能怎么创建jquery对话框呢?

更新

为了清楚起见,这是我的整个html页面

@model CardSite.Models.Card
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/jquery-ui-1.10.4.custom.min.js"></script>
@{
    ViewBag.Title = "Card";
}
<h2>New card type</h2>
@using (Html.BeginForm("CreateCard", "Card", FormMethod.Post))
{
    @Html.AntiForgeryToken()
    <div class="form-group">
        @Html.LabelFor(m => m.Name)
        <div class="text-box-for">
            @Html.TextBoxFor(m => m.Name)
        </div>
        @Html.LabelFor(m => m.Attack1Id)
        <div class="text-box-for">
            @Html.TextBoxFor(m => m.Attack1Id)
        </div>
        <div id="dialog"></div>
    </div>
    <input type="submit" value="Create" class="btn btn-default" />
}

<script type="text/javascript">
    $(document).ready(function () {
        $("#Attack1Id").click(function () {
            var location = $.find("#dialog");
            $(location).dialog({
                title: "Dialog box",
                height: 300,
                modal: true,
                open: function (event, ui) {
                },
                on: ('click', '.table a', function () {
                    alert($(this).closest('tr').find('td:first').text())
                })
            })
        });
    });
</script>

---更新---

我刚刚更新了我的代码,使其看起来像这个

<script type="text/javascript">
    $(document).ready(function () {
        $("#Attack1Id").click(function () { 
            $("#dialog").dialog({
                title: "Dialog box",
                height: 300,
                modal: true,
                open: function (event, ui) {
                    $(this).load("@Url.Action("FileTables", "Card")");
                },
                on: ('click', '.table a', function () {
                    alert($(this).closest('tr').find('td:first').text())
                })
            });
        });
    });
    $(document).ready(
            $("#dialog").dialog({
                title: "Dialog box",
                height: 300,
                modal: true,
                open: function(event, ui) {
                    $(this).load("@Url.Action("FileTables", "Card")");
                },
                on: ('click', '.table a', function(){
                    alert($(this).closest('tr').find('td:first').text())
                })
            })
        );
</script>

模态工作,它出现在页面的开头,我可以关闭,然后点击输入框,它再次出现。但如果我关闭模态,重新打开模态,然后点击视图,它会发出两个警报,就像它创建了不止一个。。。关于如何解决这个问题有什么想法吗?

$.find$('selector')的使用之间似乎存在一些差异。

此代码返回JavaScriptArray对象,因此jQuery的任何函数都不能应用于结果集。即使结果集看起来是相同的。

见此贴

您是否尝试过使用$("#dialog")来选择对话框?

<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/jquery-ui-1.10.4.custom.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
    $("#Attack1Id").click(function () { 
        $("#dialog").dialog({
            title: "Dialog box",
            height: 300,
            modal: true,
            open: function (event, ui) {
                $(this).load("@Url.Action("FileTables", "Card")");
            },
            on: ('click', '.table a', function () {
                alert($(this).closest('tr').find('td:first').text())
            })
        });
    });
});
</script>

更新:

我觉得你的页面中没有调用你的脚本引用。尝试用以下代码替换脚本引用。

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js" type="text/javascript"></script>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>