[英]JQuery get select element inside table
I have the following table element which has a select element in its td. 我有以下表格元素,其td中具有一个select元素。 The table id (table1 in the example) can keep changing. 表ID(示例中为table1)可以不断更改。 So, how can I fetch the selected option using table ID in JQuery? 那么,如何在JQuery中使用表ID来获取选定的选项?
<table class="indexViews" id = "table1">
<tr>
<td align="center", width="10%" valign="middle"></td>
<td align="center", width="70%" valign="middle">
<select id="indexViewsList" class="indexViewsListWnd" onChange="switchIndexView(this)">
<option id="0" value="0" selected="selected">Index Quick View</option>
<option id="1" value="1">Identifier View</option>
<option id="2" value="2">Commodity</option>
</select></td>
<td align="right", width="10%" valign="middle"><input class="searchIcon" type="image" src="../../images/downloadIcon.gif" alt="Submit" onClick="downloadIndexFile()"></input></td>
</tr>
</table>
I don't understand why your id keep changing. 我不明白您的身分证为何不断变更。 But maybe you will want to iterate through your table using jquery selector on class name. 但是也许您会想使用类名称上的jquery选择器来遍历表。
var lstIndexView = $(".indexViews .indexViewsListWnd");
http://api.jquery.com/class-selector/ http://api.jquery.com/class-selector/
尝试下面的代码
var selectedValue= $(".indexViews .indexViewsListWnd").val();
You can use this selector in jQuery $('table[id^="table"]')
您可以在jQuery $('table[id^="table"]')
使用此选择器
This is how you get it using table id. 这是使用表ID的方式。
$('#table1 #indexViewsList').val();
But better you get this select directly: 但是更好的是,直接选择此选项:
$('#indexViewsList').val();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.