javascript - Bootstrap Modal JS 未捕获类型错误 : undefined is not a function

标签 javascript jquery twitter-bootstrap bootstrap-modal

我有一个模态,我正尝试使用 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/

相关文章:

css - 在 Bootstrap 轮播中设置全宽/高度标题时出现问题

html - 水平对齐缩略图

javascript - 尝试让 .modal ('show' )从右侧而不是顶部滑动元素

javascript - 使用 setItem 设置多个状态值和使用 useEffect 这样做有什么区别?

javascript - 基于 DOM 的跨站点脚本示例 : Java Script does not get executed

javascript - Mootools 颜色即时变形

php - 使用 jQuery 的可折叠菜单

jquery - 如何在到达页面底部后删除类

ruby-on-rails - Rails - Twitter Bootstrap i18n - 验证

javascript - 刷卡器 : second instance of swiper not initializing