2017-08-10 2 views
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> 
+7

jQueryをインポートしていません。 – Pointy

+0

ありがとう!とった!私は

関連する問題