回答
这应该让你开始。请注意,我将该单元格内容用于该选项的值和文本。你可能需要改变这个,但从这个问题还不清楚。
var items=[], options=[];
//Iterate all td's in second column
$('#tableId tbody tr td:nth-child(2)').each(function(){
//add item to array
items.push($(this).text());
});
//restrict array to unique items
var items = $.unique(items);
//iterate unique array and build array of select options
$.each(items, function(i, item){
options.push('<option value="' + item + '">' + item + '</option>');
})
//finally empty the select and append the items from the array
$('#selectId').empty().append(options.join());
在项目分配中缺少一个= = – 2009-08-06 10:10:53
Cheers Russ,好现场 – redsquare 2009-08-06 10:12:17
@redsquare 我在这里搜索了一些相同的东西。如何为该值设置辅助数组? options.push(''); – trobbins26 2012-11-29 06:04:54
你可以使用jQuery的每个函数:
function FillSelect(){
var vals = new Array();
var i=0;
var options='';
$("#tbl tr:gt(0) td:nth-child(2)").each(function(){
var t=$(this).html();
if($.inArray(t, vals) < 0)
{
vals[i]=t;
i++;
}
});
for(var j=0;j<i;j++)
{
options += '<option value="' + j + '">' + vals[j] + '</option>';
}
$("#sel2").html(options);
}
假设 'TBL' 是你的表的ID,“选择要填充的sel2'is ID。如果您不想排除第一行,那么您可以删除tr:gt(0)并将简单的tr置于选择器表达式中。
使用tbody作为标题行应该是一个thead – redsquare 2009-08-06 10:08:01
- 1. 获取散列表中的所有值
- 2. 获取所有选中值的列表
- 3. JavaScript/jQuery:从列中获取所有值而不重复
- 4. 获取列表中的所有文本框值(jQuery Sortable)?
- 5. jQuery:获取表格中的所有输入值并序列化
- 6. 从列表中获取列中所有不同的值作为数组从表
- 7. 从一个表中获取所有列的值,并从第二个表中获取其他列的值
- 8. Jquery只从复选框列表中获取所有选中的值
- 9. 从一个列表项中获取所有数据jquery mvc 4
- 10. 获取所有多个列表框值
- 11. 从列表中获取值
- 12. 从列表中获取值
- 13. 从列表中获取值
- 14. 从ASP列表框中获取所有选定的值
- 15. 获取从左表中的所有记录与计算列值
- 16. 从列表中选择获取所有组合和值
- 17. 如何从Java中的sqlQuery获取表列的所有值?
- 18. 如何从列表视图中获取所有值? Android的
- 19. SQL-从共享两列值的表中获取所有记录
- 20. 如何从Scala列表中获取所有值?
- 21. 使用JQuery获取列表框中的所有列表项?
- 22. 从NSMutableDictionary获取所有值
- 23. JQuery的获取所有数据从列表
- 24. 从arraylist中的列表框中的所有项目中获取值.Win表单
- 25. jQuery:从XML中获取所有子项
- 26. jQuery从响应中获取所有div
- 27. 调试时从数据列表中获取所有列名/列值
- 28. ListCtrl - wxPython获取列中的所有值
- 29. 获取一列中所有行的值
- 30. 获取Sqllite中的所有列值android
向我们展示您到目前为止所得到的结果以及您遇到的问题。此外,还包括表格的示例源代码。 – 2009-08-06 09:44:23