我试图在一个数据表列的下拉列表中获取所选元素的值。以下是我的代码:
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>
如何获取所选选项的值,即数据状态的值,即此处数据状态为“ready-for-publishing”,与之对应的值为Ready for Publishing。
答案 0 :(得分: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();
}