【问题标题】:Uncaught TypeError: $(...).modal is not a function jquery未捕获的类型错误:$(...).modal 不是 jquery 函数
【发布时间】:2016-05-26 14:46:54
【问题描述】:

我有一个 jquery 脚本来显示模态表单

<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>


<script>
$(document).ready(function(){
    $(".manipulate").click(function(){
        $('#id_description').val();
        var item_keys = ['#id_counter', '#id_first_name','#id_middle_name', '#id_last_name', '#id_display_name', '#id_field', '#id_loa_price', '#id_basic_cert_price', '#id_written_appraisal_cost']
        for(var i=1; i<12; i++){
            var item_val = $(this).parent().parent().find('td:nth-child('+i+')')[0].innerText;
            console.log("InnerText is :"+ item_val);
            $(item_keys[i-1]).val(item_val);
        }
        $('#id_item').val($(this).attr('item_id'));
        $('#edititemModal').modal("show");
    });
});
</script>

如果我单击编辑按钮以显示模态表单,我会得到 .modal 不是函数。

【问题讨论】:

标签: javascript jquery twitter-bootstrap


【解决方案1】:
<script type="text/javascript">

不是

<script>

还要遵循正确的顺序: Bootstrap modal: is not a function

【讨论】:

  • 从 HTML 5 开始,type 属性 (a) 可选 (b) 明确建议不要将其用于包含 JavaScript 的脚本元素。
【解决方案2】:

我在 index.js 中添加库后解决了。我们认为您需要这个库,bootstrap.js 请添加到 index.js 中,我希望您的代码可以正常工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-24
    • 2018-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多