模态错误 - 未捕获类型错误:未定义不是一个函数模式 [英] Modal error - Uncaught TypeError: undefined is not a function modal

查看:287
本文介绍了模态错误 - 未捕获类型错误:未定义不是一个函数模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即时通讯使用以下code和我删除 JS遇到错误($(#deleteModal)模式(秀); )任何想法有什么可错在这里?
即时通讯使用MVC5项目

误差

未捕获类型错误:未定义不是一个函数

 <! - 模态 - >
< D​​IV CLASS =模式变脸ID =deleteModal的tabindex = - 1角色=对话框中的咏叹调-labelledby =deleteModalLabelARIA隐藏=真>
    < D​​IV CLASS =模式-对话框>
        < D​​IV CLASS =模式内容>
            < D​​IV CLASS =模头>
                <按钮式=按钮级=关闭数据解雇=模式><跨度ARIA隐藏=真>&安培;倍;< / SPAN><跨度类=SR - 只>关闭< / SPAN>< /按钮>
                < H4类=模式标题ID =deleteModalLabel>删除项目< / H4>
            < / DIV>
            < D​​IV ID =deleteModalBody级=模体>< / DIV>
            < D​​IV CLASS =模式躯>
                <按钮式=按钮级=BTN BTN-默认的数据驳回=模式>关闭< /按钮>
            < / DIV>
        < / DIV>
    < / DIV>
< / DIV><脚本>
    $(函数(){
        $(#deleteModal)模式(隐藏)。 //开始直到需要隐藏模式弹出        $(。deleteLink)。在(点击,函数(){            $获得(@ Url.Action(GetDeletePartial)',{ID:$(本).prop(ID)},功能(数据){
                $(#deleteModalBody)的html(数据);                $(#deleteModal)模式(秀)。 //现在显示模式弹出,我们有我们的局部视图
            });        });
    });
< / SCRIPT>

当我尝试它喜欢它后面的脚本具有相同的错误乞讨失败

  @section脚本
{
    <脚本SRC =〜/脚本/ jQuery的-2.1.1.min.js>< / SCRIPT>    <脚本>
        $(函数(){
            $(#deleteModal)模式(隐藏)。 //开始直到需要隐藏模式弹出            $(。deleteLink)。在(点击,函数(){                $获得(@ Url.Action(GetDeletePartial)',{ID:$(本).prop(ID)},功能(数据){
                    $(#deleteModalBody)的html(数据);                    $(#deleteModal)模式(秀)。 //现在显示模式弹出,我们有我们的局部视图
                });            });
        });
    < / SCRIPT>
}


解决方案

看来你正在尝试使用一些第三方的jQuery插件,使模型对话框,但你foget做出该插件的JavaScript文件的引用。

要确认这一点,我不知道它发生在哪一行的例外呢?它是在你准备回调的第一行的行?


  

$(#deleteModal)模式(隐藏);


如果是这样,请检查你的脚本参考。只需添加一个<脚本>标签与脚本块之前一个src到该文件。

更新:

当你的意见,该异常不会发生在该行。所以,你可以使用一个调试器(如Chrome开发者工具)来找出哪些函数调用失败。您可以设置调试器暂停在异常的excution。
在Chrome开发者工具,您可以切换到Source选项卡上,并点击启用此功能的右侧边栏的右顶部的最后一个图标。下面是与快照一个真棒答案:<一href=\"http://stackoverflow.com/a/17324511/1817042\">http://stackoverflow.com/a/17324511/1817042

Im using the following code and I got error in delete in the JS($("#deleteModal").modal("show");),any idea what can be wrong here ? Im using MVC5 project

the error is

Uncaught TypeError: undefined is not a function

<!-- 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.

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");

If so, please check your script reference. Just add a <script> tag with a src to that file before your script block.

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. 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. Here's an awesome answer with snapshots: http://stackoverflow.com/a/17324511/1817042

这篇关于模态错误 - 未捕获类型错误:未定义不是一个函数模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆