簡體   English   中英

為什么在Fiddle中工作的代碼無法在在線html編輯器中工作?

[英]Why code that is working in Fiddle not working at online html editor?

我知道這是無關緊要的問題,但是我遇到了一些困難。 我在小提琴https://jsfiddle.net/ew5y6pd1/4/上找到了一個代碼,它可以正常工作,但是當我復制並放置在線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>

JS Fiddle的屏幕截圖

JS Fiddle實例加載提供$函數的jQuery庫

您需要下載該庫(或找到托管版本的URL),並包括一個<script>元素,該元素會在運行依賴於該庫的腳本之前加載該庫。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM