我想通過tablesorter插件將過濾的記錄寫入csv格式的外部文件。我正在關注this answerMottie,創建Tablesorter插件。在FireBug錯誤控制檯中,出現錯誤,說Tablesorter - >將過濾的數據提取到csv文件
TypeError:$(...)。on不是函數 $('。export')。on('click',function(){
這是我的文件中使用的tablesorter提取CSV格式的記錄,
<%@page import="java.util.Iterator"%>
<%@page import="java.util.ArrayList"%>
<%
ArrayList<ArrayList<String>> resultsetlist = (ArrayList<ArrayList<String>>) request.getAttribute("SearchRecordsList");
%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<title>Research Records</title>
<!-- jQuery -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.js"></script>
<!-- Demo stuff -->
<link class="ui-theme" rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/cupertino/jquery-ui.css">
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7/jquery-ui.min.js"></script>
<link href="js/tablesorter/docs/css/prettify.css" rel="stylesheet">
<script src="js/tablesorter/docs/js/prettify.js"></script>
<script src="js/tablesorter/docs/js/docs.js"></script>
<!-- Tablesorter: required -->
<link rel="stylesheet" href="js/tablesorter/css/theme.blue.css">
<script src="js/tablesorter/js/jquery.tablesorter.js"></script>
<script src="js/tablesorter/js/jquery.tablesorter.widgets.js"></script>
<script>
$(function() {
$('table').tablesorter({
theme : 'blue',
widgets: ['zebra', 'filter' ]
});
});
$('.exportcsv').on('click', function(){
var csv = [];
// find only visible rows; we're ignoring filtered/hidden rows
$('table').find('tbody tr:visible').find('td').each(function(){
alert("Value of text" + $(this).text());
csv.push($(this).text());
});
// do what you want with the csv data here
$('textarea').val(csv.join(','))
});
</script>
<link rel="stylesheet" type="text/css" href="stylesheet1.css">
<title>JSP Page</title>
</head>
<body>
<table class="tablesorter" id="tablesorter-id-variable">
<thead>
<tr>
<%
int index = 0;
String s = "null";
Iterator itrcol = resultsetlist.iterator();
if (itrcol.hasNext()) {
ArrayList<String> col_record = (ArrayList<String>) itrcol.next();
for (index = 0; index < col_record.size(); index++) {
s = col_record.get(index);
%>
<th>
<% out.println(s);%>
</th>
<%
} // End of -for-
%>
</tr>
<%
} //end if
%>
</thead>
<tbody>
<tr>
<%
Iterator itr = resultsetlist.iterator();
itr.next();
while (itr.hasNext()) {
ArrayList<String> each_record = (ArrayList<String>) itr.next();
for (index = 0; index < each_record.size(); index++) {
s = each_record.get(index);
%>
<td>
<% out.println(s);%>
</td>
<%
} // End of -for-
%>
</tr>
<%
} //end while
%>
</tbody>
</table>
<button class="exportcsv">export csv</button><br>
<textarea cols="40" rows="10"></textarea>
</body>
</html>
這可能是可能的錯誤在上面的代碼中提前:)
更新感謝:?解決方案
這兩個答案都是對的!很難過,我可以只接受一個:(
問題是我使用的是一個早於1.4的Jquery版本,所以將它升級到最新的google cdn's-1.8,解決了這個問題。 :)
嗯,還是同樣的錯誤,先生:( – Learner 2013-04-10 22:08:38
http://api.jquery.com/on/看看。我想想$()。on只存在於jQuery 1.7+中,你正在使用jQuery 1.4,試着用一個新版本 – 2013-04-11 18:43:57
Spon!你是對的,只需檢查一下,它工作正常:)謝謝! – Learner 2013-04-12 06:34:47