0
我知道這種無關緊要的問題,但我有一些困難。我發現代碼在小提琴https://jsfiddle.net/ew5y6pd1/4/及其工作perfeclly,但是當我複製並放置一個在線HTML編輯器的數據不append.Below顯示我複製到在線HTML編輯器的代碼。我錯過任何圖書館嗎?爲什麼在小提琴中工作的代碼不能在在線html編輯器中工作?
<!Doctype html>
<html>
<head>
<style>
th, td { border: 1px solid black;}
</style>
<script>
$(document).ready(function() {
$("#add").on('click', function() {
var user = {
Id: '',
Name: ''
}
var row = $('<tr/>');
user.Id = $("#id").val();
user.Name = $("#Name").val();
row.append($('<td/>').text(user.Id));
row.append($('<td/>').text(user.Name));
$("#reservations tbody").append(row);
});
$('#sort').on('click', function(){
var rows = $('#reservations tbody tr').get();
rows.sort(function(a, b) {
var A = $(a).children('td').eq(0).text().toUpperCase();
var B = $(b).children('td').eq(0).text().toUpperCase();
if(A < B) {
return -1;
}
if(A > B) {
return 1;
}
return 0;
});
$.each(rows, function(index, row) {
$('#reservations').children('tbody').append(row);
});
})
});
</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>
您未導入jQuery。 – Pointy
老兄謝謝!得到它了!我想念