Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用数据表中的单元格值读取下拉选择?_Javascript_Jquery_Asp.net Mvc_Datatable_Dropdown - Fatal编程技术网

Javascript 如何使用数据表中的单元格值读取下拉选择?

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>

我有这个Jquery函数从Jquery数据表读取和返回数据。 我可以读取单元格值,但在下拉列表中返回整个选项列表。我尝试了几种不同的方法,但还是做不好。如何将其修改为仅在最后一列中获取选定值,而在其他列中获取其他单元格值

我的桌子

<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;
}