简体   繁体   English

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

[英]Modal error - Uncaught TypeError: undefined is not a function modal

Im using the following code and I got error in delete in the JS($("#deleteModal").modal("show"); ),any idea what can be wrong here ? 我正在使用下面的代码,但在JS($("#deleteModal").modal("show"); )中删除时出错,任何想法在这里会出错吗? Im using MVC5 project 我正在使用MVC5项目

the error is 错误是

Uncaught TypeError: undefined is not a function 未捕获的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>

when I try it like following it fail in the begging of the script with the same error 当我尝试跟随它时,它以相同的错误请求脚本失败

@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>
}

It seems that you are attempting to make a model dialog using some third-party jQuery plugin, but you foget to make a reference to that plugin's javascript file. 似乎您正在尝试使用某些第三方jQuery插件进行模型对话框,但是您想引用该插件的javascript文件。

To confirm this, i wonder which line does the exception occurs on? 为了确认这一点,我想知道异常发生在哪一行? Is it on the line of first line of your ready callback? 它在您准备好的回调的第一行上吗?

$("#deleteModal").modal("hide"); $( “#deleteModal”)模式( “隐藏”)。

If so, please check your script reference. 如果是这样,请检查您的脚本参考。 Just add a <script> tag with a src to that file before your script block. 只需在脚本块之前将带有src的<script>标记添加到该文件即可。

Update: 更新:

As you comments, the exception does not occurs on that line. 如您所言,该行不会发生异常。 So you may use a debugger(such as Chrome developer tools) to find out which function-call fails. 因此,您可以使用调试器(例如Chrome开发人员工具)来找出哪个函数调用失败。 You can set the debugger to pause the excution on exceptions. 您可以将调试器设置为在例外情况下暂停执行。 In chrome developer tools, you can switch to Source tab and click the last icon on right-top of the side-bar on the right to enable this feature. 在chrome开发人员工具中,您可以切换到“来源”标签,然后点击右侧侧栏右上角的最后一个图标以启用此功能。 Here's an awesome answer with snapshots: https://stackoverflow.com/a/17324511/1817042 这是一个很棒的快照答案: https : //stackoverflow.com/a/17324511/1817042

Had the same error on standalone plain old HTML+Javascript page. 在独立的普通旧HTML + Javascript页面上发生了相同的错误。

Apparently caused by socket.io.js which script tag was initially placed after jquery and bootstrap.js script tags. 显然是由socket.io.js引起的,该脚本标签最初放置在jquery和bootstrap.js脚本标签之后。

Moving socket.io.js script tag before jquery and bootstrap resolved the issue for me. 在jquery和bootstrap之前移动socket.io.js脚本标记可以为我解决此问题。

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

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