2012-01-18 19 views
1

私は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>"); 
    }); 
} 
+1

なぜjQueryを2回組み込んでいますか? –

+0

私は例でそれを見ましたが、それはまた、tablesorterのウェブページにもリストされています。 – Brandon

答えて

4

あなたがあるべきクロージング>

<script type="text/javascript" src="jquery.tablesorter.js"</script> 

が欠落している

<script type="text/javascript" src="jquery.tablesorter.js"></script> 

編集:アウト以下

Marek Karbarzとしてのポイントは、あなたもこのラインでクロージング>が欠落している:あなたはしかし、二回のjQueryを含めている理由

<script type="text/javascript" src="jquery-latest.js"</script> 

わかりません。

+2

jquery.latest.jsのそれ以上の行と同じ –

+0

ありがとう@MarekKarbarz、私はそれを含めて私の答えを編集しました。 –

+0

ありがとう!今、私は実際にそれを私に並べ替えることに問題があります。 – Brandon

関連する問題