Javascript 如何使用数据表中的单元格值读取下拉选择?
我有这个Jquery函数从Jquery数据表读取和返回数据。 我可以读取单元格值,但在下拉列表中返回整个选项列表。我尝试了几种不同的方法,但还是做不好。如何将其修改为仅在最后一列中获取选定值,而在其他列中获取其他单元格值 我的桌子Javascript 如何使用数据表中的单元格值读取下拉选择?,javascript,jquery,asp.net-mvc,datatable,dropdown,Javascript,Jquery,Asp.net Mvc,Datatable,Dropdown,我有这个Jquery函数从Jquery数据表读取和返回数据。 我可以读取单元格值,但在下拉列表中返回整个选项列表。我尝试了几种不同的方法,但还是做不好。如何将其修改为仅在最后一列中获取选定值,而在其他列中获取其他单元格值 我的桌子 <table id="example" class="display" style="width:100%"> <thead> <tr> <th></th>
<table id="example" class="display" style="width:100%">
<thead>
<tr>
<th></th>
<th name="nn">Column0</th>
<th name="nm">Column1</th>
<th name="no">Column2</th>
<th name="np">Column3</th>
<th name="nq">Column4</th>
<th>select</th>
</tr>
</thead>
</table>
谢谢你你有$。每个函数和$(这个)都是父元素
if($(this)。$headers==“select”){
尝试在第二个$之前添加一些变量。每个都需要向我们显示一个典型行的html。(并且您的
if($(this)。$headers==“select”){
没有意义,其中的代码永远不会执行)
function tableToJSON(tblObj) {
var data = [];
var $headers = $(tblObj).find("th");
var $rows = $(tblObj).find("tbody tr").each(function (index) {
$cells = $(this).find("td");
data[index] = {};
$cells.each(function (cellIndex) {
if ($(this).$headers == "select") {
//data[index][$($headers[cellIndex]).html()] = $(this).html();
data[index][$($headers[cellIndex]).html()] = $(this).find('select').val();
}
else
{
data[index][$($headers[cellIndex]).html()] = $(this).html();
}
});
});
return data;
}