Javascript 为函数(jQuery中的每个语句)分配的变量没有值
我正在尝试使用这个来自GitHub的jQuery下拉过滤器插件。在我的例子中,表格格式如下:Javascript 为函数(jQuery中的每个语句)分配的变量没有值,javascript,jquery,jquery-plugins,Javascript,Jquery,Jquery Plugins,我正在尝试使用这个来自GitHub的jQuery下拉过滤器插件。在我的例子中,表格格式如下: <table id="table_2"> <thead> <tr> <th> Items </th> <th> Quantity </th> </tr> </thead> <tbody> <tr>
<table id="table_2">
<thead>
<tr>
<th> Items </th>
<th> Quantity </th>
</tr>
</thead>
<tbody>
<tr>
<td> Apple </td>
<td> 20 </td>
</tr>
<tr>
<td> Orange </td>
<td> 20 </td>
</tr>
</tbody>
</table>
项目
量
苹果
20
橙色
20
因此,重新建模插件以适应这种情况是必要的:
var table = $(this);
$('thead tr th:visible', table).each(function(index) {
var selectbox = $('<select>');
var values = [];
var opts = new Array();
selectbox.append('<option value="--all--">' + $(this).text() + '</option>');
for(var noOfTr = 0; noOfTr<2; noOfTr++) {
var tr = $('tbody tr:eq('+ noOfTr +')',table);
var col = tr.find('td:eq(' + (index) + ')').each(function(index) {
var cellVal = escape($.trim($(this).text()));
if(cellVal.length == 0) {
cellVal = '--empty--';
}
$(this).attr('ddtf-value', cellVal);
if($.inArray(cellVal, values) === -1) {
var cellText = $.trim($(this).text());
if(cellText.length == 0) {cellText = '--Empty--';}
values.push(cellVal);
opts.push({val:cellVal, text:cellText});
}
});
}
}
var-table=$(此);
$('thead tr th:visible',table.)。每个(函数(索引){
var selectbox=$('');
var值=[];
var opts=新数组();
selectbox.append(“”+$(this.text()+“”);
对于(var noOfTr=0;noOfTr尝试使用:
var col = tr.find('td:eq(' + (noOfTr) + ')').each(function(index) {
而不是:
var col = tr.find('td:eq(' + (index) + ')').each(function(index) {
由于自动递增变量是noOfTr
而不是index
,我现在编辑了代码,以便它清楚地说明什么是“index”和“$(this)”的含义。