Tablesorter – >将过滤后的数据提取到csv文件

我想将通过tablesorter插件过滤的记录写入csv格式的外部文件。 我跟随这个回答是Mottie ,Croporter插件的创建者。 在FireBug错误控制台中,我收到错误消息

TypeError:$(…)。on不是函数$(’。export’)。on(’click’,function(){

这是我的文件使用tablesorter来提取csv格式的记录,

  <% ArrayList<ArrayList> resultsetlist = (ArrayList<ArrayList>) request.getAttribute("SearchRecordsList"); %>       Research Records              $(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(',') ) });   JSP Page    <% int index = 0; String s = "null"; Iterator itrcol = resultsetlist.iterator(); if (itrcol.hasNext()) { ArrayList col_record = (ArrayList) itrcol.next(); for (index = 0; index  <% Iterator itr = resultsetlist.iterator(); itr.next(); while (itr.hasNext()) { ArrayList each_record = (ArrayList) itr.next(); for (index = 0; index  

在上面的代码中可能出现什么错误? 提前致谢 :)

更新:解决方案

两个答案都是正确的! 很遗憾我只能接受一个:(

问题是我使用的是一个与1.4一样久的Jquery版本。 因此将其升级到最新的谷歌cdn – 1.8,解决了这个问题。 感谢答案:)

使用新版本的jQuery,因为$()。on仅在jQuery 1.7+中可用,并且您使用的是jQuery 1.4。

  

您可以将它用于安全性,许多JavaScript库使用$作为默认值。 在这个.ready()中,$指的是jQuery对象。

 jQuery(document).ready(function($) { $(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(',') ) }); }); 

jQuery v1.4没有on()函数,改为使用bind()代替。

 $('.exportcsv').bind('click', function(){ 

或者将您正在使用的jQuery版本更新为1.7+版本