jquery read table

本文介绍了一种使用jQuery操作DOM的方法,具体展示了如何从表格中提取特定列的数据,并将其转换为不含重复项的下拉选项列表。该过程涉及遍历表格行、获取指定列的内容、去除重复项并最终填充到选择框中。

$('#mytable tr').each(function() {
var customerId = $(this).find("td").eq(2).html();
});


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() );
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值