私はXMLファイルをテーブルに解析しており、jquery tablesorterを使用したいと考えています。私は多くのことを試みましたが、そのうち何も働いていませんでした。私は最初にAJAXを介してXMLファイルを解析してから、テーブル上でtablesorterを呼び出していました。今私のコードを持っている方法で、テーブル上でtablesorterを呼び出し、AJAXを実行してから$("#table).trigger("update")
でテーブルを更新しています。私はそれが最初の方法であろうと2番目の方法であろうとも、このエラーを受けています: "$(#table).tablesorter()は関数ではありません"。何か案は? JSとHTMLのコードを以下に示します。JQuery Tablesorterは関数ではありません
HTML:
<html>
<head>
<title>Read XML</title>
<script type="text/javascript" src="jquery-1.7.1.js"></script>
<script type="text/javascript" src="jquery-latest.js"</script>
<script type="text/javascript" src="jquery.tablesorter.js"</script>
<script type="text/javascript" src="custom.js"></script>
</head>
<body>
<table id="table" border="1">
<thead>
<tr>
<th>Item #</th>
<th>Shape</th>
<th>Weight</th>
<th>Color</th>
<th>Clarity</th>
<th>Price($)</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</body>
</html>
JS:
$(document).ready(function() {
$("#table").tablesorter();
$.ajax({
type: "GET",
url: "tutorial.xml",
dataType: "xml",
success: parseXml
});
$("#table").trigger("update");
});
function parseXml(xml)
{
$(xml).find("diamond").each(function()
{
$("#table tbody").after("<tr><td>" + $(this).find("id").text() +
"</td><td>" + $(this).find("shape").text() + "</td><td>" + $(this).find("weight").text() +
"</td><td>" + $(this).find("color").text() + "</td><td>" + $(this).find("clarity").text() +
"</td><td>" + $(this).find("price").text() + "</td></tr>");
});
}
なぜjQueryを2回組み込んでいますか? –
私は例でそれを見ましたが、それはまた、tablesorterのウェブページにもリストされています。 – Brandon