模态错误 - 未捕获的TypeError:undefined不是函数模态

时间:2014-07-27 07:44:17

标签: javascript jquery asp.net asp.net-mvc twitter-bootstrap

我使用以下代码,我在JS($("#deleteModal").modal("show");中删除了错误,不知道这里有什么问题吗? 我正在使用MVC5项目

错误是

未捕获的TypeError:undefined不是函数

<!-- Modal -->
<div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="deleteModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title" id="deleteModalLabel">Delete Item</h4>
            </div>
            <div id="deleteModalBody" class="modal-body"></div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>

<script>
    $(function () {
        $("#deleteModal").modal("hide");  // initially hides the modal pop-up until needed

        $(".deleteLink").on("click", function () {

            $.get('@Url.Action("GetDeletePartial")', { id: $(this).prop("id") }, function (data) {
                $("#deleteModalBody").html(data);

                $("#deleteModal").modal("show");  // shows the modal pop-up now that we have our partial view
            });

        });
    });
</script>

当我尝试它时,如果它在脚本的乞求失败时出现同样的错误

@section scripts
{
    <script src="~/Scripts/jquery-2.1.1.min.js"></script>   

    <script>
        $(function () {
            $("#deleteModal").modal("hide");  // initially hides the modal pop-up until needed

            $(".deleteLink").on("click", function () {

                $.get('@Url.Action("GetDeletePartial")', { id: $(this).prop("id") }, function (data) {
                    $("#deleteModalBody").html(data);

                    $("#deleteModal").modal("show");  // shows the modal pop-up now that we have our partial view
                });

            });
        });
    </script>
}

2 个答案:

答案 0 :(得分:1)

您似乎正在尝试使用某些第三方jQuery插件创建模型对话框,但您很想引用该插件的javascript文件。

为了确认这一点,我想知道发生异常的哪一行?它是否在准备回调的第一行?

  

$(&#34;#deleteModal&#34)的模态。(&#34;隐藏&#34);

如果是,请检查您的脚本参考。只需添加一个&lt; script&gt;在脚本阻止之前用src标记该文件。

更新

在您发表评论时,该行不会发生异常。因此,您可以使用调试器(例如Chrome开发人员工具)来找出哪个函数调用失败。您可以将调试器设置为暂停对异常的执行。 在Chrome开发人员工具中,您可以切换到“源”选项卡,然后单击右侧边栏右上角的最后一个图标以启用此功能。这是快照的一个很棒的答案:https://stackoverflow.com/a/17324511/1817042

答案 1 :(得分:0)

在独立的普通旧HTML + Javascript页面上出现相同的错误。

显然由socket.io.js导致哪个脚本标记最初放在jquery和bootstrap.js脚本标记之后。

在jquery和bootstrap之前移动socket.io.js脚本标记为我解决了这个问题。

相关问题