当我尝试使用$("#modalPlaced").modal("show")
时,出现Uncaught TypeError: (0 , _jquery2.default)(...).modal is not a function
但是正确加载了jQuery,因为这段代码正常工作:
$.ajax({
url: form.action,
data: $(form).serialize(),
type: 'POST',
dataType: 'json',
success: (data) => {
if (data.message === 'Success!') {
$("[data-dismiss=modal]").trigger({type: "click"});
我想知道是否有办法显示ID为modalPlaced
的模态?
或者我该如何解决.modal is not a function
错误?
答案 0 :(得分:0)
好像你没有包含js文件。 尝试将以下内容添加到页面上的head标记:
<script src='js/bootstrap.min.js'></script>
答案 1 :(得分:0)
以下作品。你能告诉我这是否适合你吗?
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>IndexStackOverflow102</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script type="text/javascript">
$(function () {
$("#modalPlaced").modal('show');
})
</script>
</head>
<body>
<div>
<div id="modalPlaced" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-content">
<div class="modal-body">
<p>Popup</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</body>
</html>