我創建了一個列出jQuery Datatable中玩家統計數據的頁面。到目前爲止,我已經能夠顯示實際數據庫中的數據,但我無法添加任何新玩家。我創建了一個添加按鈕,並從輸入新玩家開始,但是我收到此錯誤「Datatables warning:table id = test - 請求未知參數'id',用於第3行第0列。有關此錯誤的更多信息,請參見https://datatables.net/manual/tech-notes/4 「並點擊確定後,空白行被添加到表中。這裏是我的jQuery代碼:JQuery Datatables從文本框中添加新行
$(document).ready(function() {
$('#test').DataTable({
"ajax":{
"url": "players.json",
"dataSrc":""
},
"columns": [
{"data": "id"},
{ "data": "playername" },
{ "data": "points" },
{ "data": "steals" },
{ "data": "blocks" },
{ "data": "assists" },
{ "data": "mpg" },
{ "data": "shootingpercentage" },
{ "data": "threepointpercentage" }
]
});
var dTable = $('#test').DataTable();
$('#addbtn').on('click', function(){
dTable.row.add([
$('#id').val(),
$('#player').val(),
$('#points').val(),
$('#steals').val(),
$('#blocks').val(),
$('#assists').val(),
$('#mpg').val(),
$('#shotpct').val(),
$('#3pct').val()
]).draw();
});
而對於輸入文本框的HTML和表:
<body>
<div id="main" class="container">
<input type="text" name="id" id="id" placeholder="Id" />
<input type="text" name="player" id="player" placeholder="Player"/>
<input type="text" name="points" id="points" placeholder="Points" />
<input type="text" name="steals" id="steals" placeholder="Steals" />
<input type="text" name="blocks" id="blocks" placeholder="Blocks" />
<input type="text" name="assists" id="assists" placeholder="Assists" />
<input type="text" name="mpg" id="mpg" placeholder="MPG" />
<input type="text" name="shotpct" id="shotpct" placeholder="Shot %" />
<input type="text" name="3pct" id="3pct" placeholder="3 %" />
<input type="button" value="add player" id="addbtn" />
<br />
<br />
<input type="button" value="Delete selected row" id="dltbtn" />
<div id="table">
<table id="test" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Points</th>
<th>Steals</th>
<th>Blocks</th>
<th>Assists</th>
<th>MPG</th>
<th>Shot %</th>
<th>3 %</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Id</th>
<th>Name</th>
<th>Points</th>
<th>Steals</th>
<th>Blocks</th>
<th>Assists</th>
<th>MPG</th>
<th>Shot %</th>
<th>3 %</th>
</tr>
</tfoot>
</table>
</div>
</div>
</body>
我只需要能夠讓我把文本框中的數據顯示在數據表。
爲什麼文件準備好了? - > ** http://modernweb.com/2013/05/06/5-things-you-should-stop-doing-with-jquery/** – davidkonrad
@davidkonrad我試着把它移到文檔之外準備好了,現在我不要有任何反應,所以我不認爲這是問題所在。 – hereswilson