【发布时间】:2017-04-02 04:23:12
【问题描述】:
$(document).ready(function() {
var user = {
Id: '',
Name: ''
}
var td = "";
var row = "";
$("#Add").click(function() {
var userList = [];
user.Id = $("#id").val();
user.Name = $("#Name").val();
userList.push(user);
userList.forEach(function(u) {
row += "<td>" + u.Id + "</td>"
row += "<td>" + u.Name + "</td>"
});
var tr = "<tr>" + row + "</tr>";
$("#reservations").append(tr);
tr = " ";
row = " ";
});
});
<style> th,
td {
border: 1px solid black;
}
</style>
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.12.0.min.js">
</script>
</head>
<body>
<input type="text" id="id" />
<input type="text" id="Name" />
<input type="button" id="Add" value="Add" />
<br />
<input type="button" id="sort" value="sort" />
<table id="reservations">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</body>
</html>
我创建了一个动态 html 表。在该表中,我动态添加行和数据。我使用了两个文本框和一个添加按钮。我所要做的就是在文本框中输入数据并按添加按钮,数据仅使用 JQuery 添加到表中。检查我共享的 sn-p。我需要启用此代码上的数据排序和搜索。
【问题讨论】:
-
请检查datatables.net并使用它:)
标签: jquery html html-table