鍍金池/ 問答/HTML/ bootstrapTable數據不能加載,按照文檔寫的

bootstrapTable數據不能加載,按照文檔寫的


<html>
<head>
<link rel="stylesheet" href="bootstrap.min.css">
<link rel="stylesheet" href="bootstrap-table.css">

<script src="jquery.min.js"></script>
<script src="bootstrap.min.js"></script>
<script src="bootstrap-table.js"></script>
<-- put your locale files after bootstrap-table.js -->
<script src="bootstrap-table-zh-CN.js"></script>

<script>
/*
$('#table').bootstrapTable({
    url: '/data.json',
    columns: [{
        field: 'id',
        title: 'Item ID'
    }, {
        field: 'name',
        title: 'Item Name'
    }, {
        field: 'price',
        title: 'Item Price'
    }]
});
*/

$('#tt11').bootstrapTable({
    columns: [{
        field: 'id',
        title: 'Item ID'
    }, {
        field: 'name',
        title: 'Item Name'
    }, {
        field: 'price',
        title: 'Item Price'
    }],
    data: [{
        id: 1,
        name: 'Item 1',
        price: '$1'
    }, {
        id: 2,
        name: 'Item 2',
        price: '$2'
    }]
});
</script>
</head>
<body>
<table id="tt11"></table>
</body>
</html>

這個代碼有什么問題,怎么不好使呢,請指教

回答
編輯回答
使勁操

操作dom的js代碼最好放在html語法的下面。
在你這段代碼里面,你執(zhí)行$('#tt11').bootstrapTable()的時候,你的#tt11這個dom根本還沒渲染出來,就沒dom可操作,就會出現加載數據錯誤的問題~

2017年6月29日 16:34
編輯回答
莓森
$(document).ready(function () { 

});

應該把代碼放這里

2018年4月24日 06:23