如何使用jQuery和Ajax在html文件下显示和排序xml文件的数据

时间:2019-06-20 00:44:43

标签: jquery xml sorting

如何使用jQuery和Ajax在html文件下显示和排序xml文件的数据。...

这是我的xml文件的代码:(History.xml)

<History>
<Entry LibID="5177412" Time="1557027746">ddd</Entry>
<Entry LibID="5177412" Time="1557027776">ccc</Entry>
<Entry LibID="5177412" Time="1557027779">bbb</Entry>
<Entry LibID="5177412" Time="1557027793">aaa</Entry>
</History>

这是我的HTML文件的代码:(History.html)

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>history</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
</head>
<body>
 <script type="text/javascript">
    $(document).ready(function () {
    $.ajax({
        type: "GET",
        url: "History.xml",
        cache: false,
        dataType: "xml",
          success: function(xml) {
            $(xml).find('History').each(function(){
                $(this).find("Entry").each(function(){
                    var Entry= $(this).text();
                    $('#people').append('<tr><td>' + Entry+ '</td></tr>');
            });
            });
        }  
     });
 });
</script>
<table border="0"  id="people" align="left">
<tr><td class="auto-style1" bgcolor="#006666">History</td></tr>
</table>
</body>
</html>

在Microsoft Edge浏览器上运行后(它在chrome下不起作用,我也很沮丧),它将出现:

ddd 抄送 bbb aaa

请问,如何根据xml文件的“时间”属性将它们排序为:

aaa bbb 抄送 ddd

谢谢

0 个答案:

没有答案