我使用插件http://tablesorter.com/docs/为了在javascript中对我的表格进行排序并过滤列,我的问题是我不想在所有列上放置过滤器,因此我使用这个:
widgetOptions : {
filter_formatter : {
1:function($cellnindx){return null;},
4:function($cell,indx){return null;}
}
}
它可以工作,但现在我想做一个脚本,不要在具有 notFiler 类的列上打印过滤器,所以我执行此脚本:
var temp = "";
var i = 0;
$(".tablesorter th").each(function()
{
if($(this).attr('class') == "notFiler")
{
if(temp != "")
{
temp += ',';
}
temp += i + ': function($cell, indx){return null;}';
}
i++;
});
它允许我生成文本,我允许我不在某些列上打印过滤器,但当我这样做时:
widgetOptions : {
filter_formatter : {
eval(temp);
}
}
我有一个 JavaScript 错误:意外的 token ;
最佳答案
不要使用评估。难道你就不能简单地这样做吗?
首先创建结果对象
var widgetOptions = {
filter_formatter: {};
};
现在只需附加到它
$(".tablesorter th").each(function(i) {
if($(this).attr('class') == "notFiler") {
widgetOptions.filter_formatter[i] = function($cell, indx){return null;};
}
});
然后,初始化表排序器
var tablesorter = $('.tablesorter').tablesorter({
widgetOptions: widgetOptions
});
关于javascript - Eval 函数或 document.write,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29847100/