我有一个模态,我正尝试使用 javascript 调用它,但在运行该代码时我从控制台收到此错误:
Uncaught TypeError: undefined is not a function
我看过类似的问题,但没有一个对我有用。我的标题看起来像这样:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.7.0/underscore-min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
模式将通过单击按钮使用 AJAX 进行填充。模态的 html 看起来像这样:
<div class="modal fade" id="edit" tabindex="-1" role="dialog" aria-labelledby="edit" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div id="slotedit"></div>
</div>
</div>
</div>
JavaScript 看起来像这样:
function getEdit(slotID) {
var xmlhttp = jQuery.noConflict();
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else {// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
//Change table element
document.getElementById("slotedit").innerHTML=xmlhttp.responseText;
$('#edit').modal('show');
}
}
xmlhttp.open("POST","getEditData.php",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("slotID=" + slotID);
}
这让我有点难过,但是 header 中 js 脚本的顺序似乎没有任何改变,并且使用该方法在另一个模态上调用模态也不起作用(表明 AJAX 可以)。
谢谢
编辑:$('#edit')... 没有修复 :(
最佳答案
我猜你在 ('#edit')
之前遗漏了 '$'
。
应该是$('#edit').modal('show');
关于javascript - Bootstrap Modal JS 未捕获类型错误 : undefined is not a function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27653144/