未捕获的TypeError:$(...)。modal不是具有远程URL的函数

时间:2016-04-28 10:41:13

标签: javascript twitter-bootstrap modal-dialog

我正在尝试在按钮的click上打开一个Bootstrap模式窗口。模态窗口打开外部页面(相同的原点)。

Please look into JS Fiddle for more clarification.

https://jsfiddle.net/deveshmishra/frubmp1y/

错误:当我点击按钮时出现错误,即:

  

未捕获TypeError:$(...)。modal不是函数。

有趣的是,每次我都没有收到此错误。有时它工作正常,但有时,它不起作用。另一件事是,它只在我加载外部页面时出现。否则它工作正常。

1 个答案:

答案 0 :(得分:-1)

解决了问题。 https://jsfiddle.net/frubmp1y/5/ 检查一下 -

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js">    </script>
</head>
<body>
<div class="container">
<h2>Open a Popup Window</h2>
<button id="openModal" type="button" class="btn btn-default">Bootstrap Popup</button>

<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">&times;</button>
            <h4 class="modal-title">Modal Header</h4>
        </div>
        <div class="modal-body">
            <p>Some text in the modal.</p>
        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
    </div>

</div>
</div>
<script>
    $(document).on("click", "#openModal", function (){
        var url = "http://testing.dev/index.html";
        $('#myModal').modal({ show: 'true', remote: url })
    });
 </script>