0

我正在尝试在数据表列的下拉列表中获取所选元素的值。以下是我的代码:

function getstate(item) {
    var rows = $("#content_objects_table").dataTable().fnGetNodes();

    for(var i=0;i<rows.length;i++)
    {
         // Get HTML of 3rd column (for example)
        console.log("item:"+item+" id:"+$(rows[i]).find("td:eq(1)").html());
        if($(rows[i]).find("td:eq(1)").html()==item){
            console.log($(rows[i]).find("td:eq(4)").div.select.data-state);
            return ($(rows[i]).find("td:eq(4)").html());
        }   
    }
};

到目前为止,我能够获得具有下拉列表的列的值。所以我得到一个如下的div:

<div class="selectorContainer assemblyCompleted" style="padding-left: 15px;">
    <select class="states" style="width: 150px;" data-objectid="Scorm123" data-state="ready-for-publishing">
        <option value="ready-for-publishing">Ready for Publishing</option>
        <option value="published">Published</option>
        <option value="rework">Rework</option>
    </select>
</div>

如何获取所选选项的值,即数据状态的值,即这里的数据状态是“准备发布”,对应的值是准备发布。

4

1 回答 1

0

尝试这个

/* cache row so don't keep creating new object*/
var $row=$(rows[i]);

if($row.find("td:eq(1)").html()==item){
       var state=$row.find("td:eq(4) select.states").data('state');
       var optionText=$row.find('option[value="'+state+'"]').text();

} 
于 2013-04-23T11:39:44.593 回答