Javascript 为什么在Fiddle中工作的代码不能在在线html编辑器中工作?
我知道这是一个无关紧要的问题,但我有一些困难。我在fiddle上发现了一个代码,它工作得很好,但是当我复制并放置在线html编辑器时,数据并没有附加。下面显示了我复制到在线html编辑器的代码。我错过图书馆了吗Javascript 为什么在Fiddle中工作的代码不能在在线html编辑器中工作?,javascript,html,Javascript,Html,我知道这是一个无关紧要的问题,但我有一些困难。我在fiddle上发现了一个代码,它工作得很好,但是当我复制并放置在线html编辑器时,数据并没有附加。下面显示了我复制到在线html编辑器的代码。我错过图书馆了吗 <!Doctype html> <html> <head> <style> th, td { border: 1px solid black;} </style> <script> $(document).re
<!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>
JS Fiddle实例加载,它提供了$function
您需要下载库或找到托管版本的URL,并在运行依赖它的脚本之前包含加载它的元素。您没有导入jQuery。谢谢!知道了!我想念耶兹兄弟!刚刚好!