【问题标题】:Bootstrap Modal JS Uncaught TypeError: undefined is not a functionBootstrap Modal JS Uncaught TypeError: undefined is not a function
【发布时间】:2014-12-26 05:29:42
【问题描述】:

我尝试使用 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);
}

有点难倒我,但是头部中js脚本的顺序似乎并没有改变任何东西,并且使用该方法在另一个模态上调用模态也不起作用(建议AJAX是可以的)。

谢谢

编辑:$('#edit')... 没有修复它:(

【问题讨论】:

    标签: javascript jquery twitter-bootstrap bootstrap-modal


    【解决方案1】:

    我猜你在('#edit')之前缺少'$'

    应该是$('#edit').modal('show');

    【讨论】:

    • 谢谢 - 不幸的是美元符号仍然给出错误
    【解决方案2】:

    另外,既然您一直在使用 jquery,为什么不使用 jQuery 方便的 $.ajax 方法 $.post

    function getEdit(id) {
      $.post('getEditData.php', { slotID: id }, function(data) {
        $('#slotedit').html(data);
        $('#edit').modal('show');
      });
    }
    

    老实说,为什么要担心 IE5 和 IE6? IE6有less than 1% usage, globally

    【讨论】:

      猜你喜欢
      • 2015-06-18
      • 1970-01-01
      • 2011-08-13
      • 2014-09-18
      • 2014-08-15
      • 2015-01-14
      • 2014-07-06
      • 2014-09-01
      • 2015-11-04
      相关资源
      最近更新 更多