如何处理“错误:未捕获的TypeError:无法读取未定义的属性'defaults'”

时间:2019-04-24 15:53:58

标签: javascript jquery html twitter-bootstrap-3

我正在尝试使用Bootstrap 3和jquery将可编辑的表加载到HTML中,但是由于某些原因,即使我正在加载所有模块,我仍不断收到Uncaught typeerror,并且在jsfiddle中运行文件没有问题但不在这里。 http://jsfiddle.net/6o3c9e4p/1/

enter image description here enter image description here

index.html

<!DOCTYPE html>

<html>

<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>

</head>
<body>

<table class="table table-striped table-bordered table-hover"  cellspacing="0" id="mainTable" data-click-to-select="true" data-show-toggle="true" data-show-columns="true" data-search="true" data-pagination="true">
    <thead>
    <tr>
        <th data-field="storeName" data-halign="center" data-align="left" data-sortable="true">Store Name</th>

        <th data-field="sales" data-halign="center" data-align="left" data-sortable="true" data-editable="true">Sales</th>

    </tr>
    </thead>

</table>

    <script src="script.js" type="text/javascript"></script>

</body>
</html>

script.js-Javascript + jQuery 2.1.0

$.fn.editable.defaults.mode = 'inline';
$.fn.editable.defaults.container = 'body';

var data = [{storeName: 'A',  sales: 'na'},
           {storeName: 'B',  sales: 'na'},
           {storeName: 'C', sales: 'na'},
           {storeName: 'D', sales: 'na'}
           ]

$('table').bootstrapTable({
    data: data,
    sortable: true,
    resizable: true,
    editable: true
});


$('.editable').click(function(){
    if($(this).next('.editable-container').width() > $(this).closest('td').width()){
        $('th:eq('+$(this).closest('td').index()+')').css('width', $(this).next('.editable-container').width()+15);
    }
});

$('.editable').on('hidden', function() {
    $('th:eq('+$(this).closest('td').index()+')').css('width', 'auto'); 
});

0 个答案:

没有答案