模态JS错误-对象不支持属性或方法“模态”

时间:2018-10-20 04:37:15

标签: jquery asp.net twitter-bootstrap bootstrap-modal

我试图显示一个模式弹出窗口,以显示网格中所选记录的详细信息。在模式弹出窗口中设置每个控件的值后,我尝试将其打开,但失败。 我已经在网站母版页中包含了所有必需的引用,但是不断收到“对象不支持属性或方法'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 个答案:

答案 0 :(得分:0)

检查您的参考资料;我认为他们彼此之间有冲突。 对引用进行注释和注释,以查找冲突。 希望会有用

答案 1 :(得分:0)

您的验证码正确

可能的问题:

  • 您需要在主体ContentPlaceHolder主体末尾应用模式HTML代码
  • 请尽量在</body>结尾处保留HTML内容
  • 在CSS中检查其他元素z-index,它可能与该模型不重叠
  • 确保它正在调用$('#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>

答案 2 :(得分:0)

谢谢大家的回复。问题似乎是母版页中以下两个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>