代码之家  ›  专栏  ›  技术社区  ›  NoBullMan

modal js error-对象不支持属性或方法“modal”

  •  2
  • NoBullMan  · 技术社区  · 6 年前

    我试图显示一个模式弹出窗口,以显示网格中选定记录的详细信息。在模态弹出窗口中设置每个控件的值后,我尝试打开它,但失败了。 我已在网站母版页中包含了所有必需的引用,但始终获取“对象不支持属性或方法‘modal’”错误:

    在母版页中:

    <head runat="server">
        <meta charset="utf-8" />
        <meta http-equiv="cache-control" content="no-cache, no-store" />
        <meta http-equiv="expires" content="0" />
        <meta http-equiv="pragma" content="no-cache" />
        <title><%: Page.Title %></title>
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
        <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery-json/2.6.0/jquery.json.min.js"></script>
        <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
        <script type="text/javascript" src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script>
    
        <script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
        <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
        <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css">
        <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css">
    
        <meta name="viewport" content="width=device-width" />
        <asp:ContentPlaceHolder runat="server" ID="HeadContent" />
    </head>
    

    javascript代码:

    function setDetailFields(record, clear) {debugger
        // populate controls in modal
        var reqID = record["RequestID"];
        ...
    
        $('#spnRequestID').text(reqID);
        ...
    
        //$('#detailModal').modal({ backdrop: 'static', keyboard: false });
        $('#detailModal').modal('show');
    }
    

    ASPX:

    <div class="modal fade" id="detailModal" role="dialog" aria-labelledby="catModalLabel" aria-hidden="true">
        <div class="modal-dialog fade in modal-lg ui-draggable">
            <div class="modal-content">    
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title">Something</h4>
                </div>
                <div class="modal-body"> 
                    ...                  
                </div>
            </div>
        </div>
    </div>
    ....
    
    3 回复  |  直到 6 年前
        1
  •  0
  •   Ali Akbar Jahanbin    6 年前

    查一下你的推荐信,我认为他们之间有冲突。 注释和反注释引用以查找冲突。 希望它有用

        2
  •  0
  •   saAction    6 年前

    你的代码是正确的

    可能的问题:

    • 您需要将模式html代码应用到最终主控形状 ContentPlaceHolder 身体接触
    • 在结束之前尽量保持HTML格式 </body> 尽可能接近
    • 检查其他元素 z-index 在css中,它可能与此模型不重叠
    • 确保它在呼叫 $('#detailModal').modal('show'); ,使用开发人员工具栏和调试器(您已经应用了 debugger )

    检查以下示例:

    $(document).ready(function () {
        $('#myBtn').click(function () {
            setDetailFields();
        })
    });
    
    function setDetailFields(record, clear) {
        // populate controls in modal
        //var reqID = record["RequestID"];
        //...
    
        //$('#spnRequestID').text(reqID);
        //...
    
        //$('#detailModal').modal({ backdrop: 'static', keyboard: false });
        $('#detailModal').modal('show');
    }
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery-json/2.6.0/jquery.json.min.js"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
    <script type="text/javascript" src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script>
    
    <script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css">
    <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css">
    
    <button class='btnup' id="myBtn">Show Modal</button>
    
    <div class="modal fade" id="detailModal" role="dialog" aria-labelledby="catModalLabel" aria-hidden="true">
        <div class="modal-dialog fade in modal-lg ui-draggable">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title">Something</h4>
                </div>
                <div class="modal-body">
                    ...
                </div>
            </div>
        </div>
    </div>
        3
  •  0
  •   NoBullMan    6 年前

    谢谢大家的回复。问题似乎是母版页中的以下两个jquery脚本引用。一旦我把它们移走,莫代尔就开始工作了。

    <body>
        <form id="MainForm" runat="server">
            <asp:ToolkitScriptManager ID="toolkitScriptMaster" runat="server" EnablePartialRendering="true" EnablePageMethods="true">
                <Scripts>
                    <asp:ScriptReference Name="jquery" />
                    <asp:ScriptReference Name="jquery.ui.combined" />
                </Scripts>
            </asp:ToolkitScriptManager>