javascript JQuery Tablesorter 不是一个函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8917715/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JQuery Tablesorter not a function
提问by Brandon
I am parsing an XML file into a table and want to use the jquery tablesorter. I've tried many things, of which none have worked. I was parsing the XML file first via AJAX and then calling tablesorter on my table. The way I have my code now, I'm calling tablesorter on my table, running AJAX, and then updating the table with $("#table).trigger("update")
. I am getting this error no matter whether I have it the first way or the second way: "$(#table).tablesorter() is not a function". Any ideas? Code is listed below for JS and HTML.
我正在将一个 XML 文件解析为一个表,并希望使用 jquery 表排序器。我尝试了很多东西,但都没有奏效。我首先通过 AJAX 解析 XML 文件,然后在我的表上调用 tablesorter。我现在拥有代码的方式是在我的表上调用 tablesorter,运行 AJAX,然后使用$("#table).trigger("update")
. 无论是第一种方式还是第二种方式,我都会收到此错误:“$(#table).tablesorter() 不是函数”。有任何想法吗?下面列出了 JS 和 HTML 的代码。
HTML:
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:
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>");
});
}
回答by Colin Brock
You are missing a closing >
你错过了一个结束 >
<script type="text/javascript" src="jquery.tablesorter.js"</script>
should be
应该
<script type="text/javascript" src="jquery.tablesorter.js"></script>
Edit:
编辑:
As Marek Karbarzpoints out below, you're also missing a closing >
on this line:
正如Marek Karbarz在下面指出的那样,您也错过了>
这条线的结尾:
<script type="text/javascript" src="jquery-latest.js"</script>
Not sure why you're including jQuery twice, however.
但是,不确定为什么要包含两次 jQuery。