【发布时间】:2020-08-16 18:43:09
【问题描述】:
我想在点击一个显示模式的链接时调用一个函数。
head 标签中的导入脚本
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
模态:
<div class="modal fade" id="modFileUpload" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Upload Plans</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form id="myform">
<div class="custom-file">
<input type="file" class="custom-file-input" id="myfile">
<label class="custom-file-label" for="customFile">Choose file</label>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal" id="closeUploadPlansModal">Close</button>
</div>
</div>
</div>
</div>
链接:
<a class="nav-link text-left" role="button" onclick="uploadFiles()" >
<i class="fa fa-upload"></i><span class="nav-text">Upload Plans</span>
</a>
上传文件功能:
function uploadFiles(){
$('#modFileUpload').modal('show'); //getting error here
}
我收到以下错误:
未捕获的类型错误:$(...).modal 不是函数
有什么方法可以显示链接的模态点击?
【问题讨论】:
-
你能把你的代码贴在你导入 bootstrap.js 等的地方吗?
-
你要么没有加载 bootstrap.js 要么多次加载 jQuery.js
-
这能回答你的问题吗? Bootstrap modal: is not a function
-
@charlietfl 我已经用我的导入脚本更新了问题,我错过了什么吗?
-
确保页面下方没有加载其他版本的 jQuery.js。另一个问题可能是使用
$()的其他库,它不再是 jQuery 对象
标签: javascript