遍历到selectMenu并获取id(Javascript \ JQuery)
Traverse to selectMenu and get id (Javascript \ JQuery)
我想获得输入的 selected 值。
仅当上升 class 是特定的 - Q01。
假设 select 菜单上没有 "name" 或 "ID",因为我在 运行 时不知道它。
<table>
<TR>
<td class="Q01" valign="MIDDLE"> <b>01.1 </b>Question 01 </td>
<TD>
<SELECT CLASS="selectMenu" ID="" NAME="">
<OPTION VALUE=""><None></OPTION>
<OPTION VALUE="2" SELECTED>2</OPTION>
<OPTION VALUE="1">1</OPTION>
</SELECT>
</TD>
</TR>
<TR>
<td class="Q01" valign="MIDDLE"> <b>01.1 </b>Question 02 </td>
<TD NOWRAP>
<SELECT CLASS="selectMenu" ID="" NAME="">
<OPTION VALUE=""><None></OPTION>
<OPTION VALUE="2">2</OPTION>
<OPTION VALUE="1">1</OPTION>
</SELECT>
</TD>
</TR>
</table>
我试过了$(".Q01:first").next('select').val();
但是它returnsundefined
编辑 - 我将 "input" 更改为 "select",我的错误。
答案编辑 - 感谢 Hello Cynogenic,我使用 "alert($('.Q01:first').next('td').find('select option:selected').val())
进一步缩小了我想要的范围,我从第一个 select 菜单中返回了 selected 选项.
首先,您有一个备用的 </TD>
标记,这意味着您的标记已损坏。
假设您删除错误标签,这将为您提供 select 元素:
$('.q1').next('td').find('select');
你必须一步步遍历文档。
next() 表示 "find the next element within this container, at this level, if it matches the specified selector"
find() 表示 "search the current element for children matching the specified selector"
alert($(".Q01:first" ).next('td').children().val());
检查下方 link :-)
我想获得输入的 selected 值。 仅当上升 class 是特定的 - Q01。 假设 select 菜单上没有 "name" 或 "ID",因为我在 运行 时不知道它。
<table>
<TR>
<td class="Q01" valign="MIDDLE"> <b>01.1 </b>Question 01 </td>
<TD>
<SELECT CLASS="selectMenu" ID="" NAME="">
<OPTION VALUE=""><None></OPTION>
<OPTION VALUE="2" SELECTED>2</OPTION>
<OPTION VALUE="1">1</OPTION>
</SELECT>
</TD>
</TR>
<TR>
<td class="Q01" valign="MIDDLE"> <b>01.1 </b>Question 02 </td>
<TD NOWRAP>
<SELECT CLASS="selectMenu" ID="" NAME="">
<OPTION VALUE=""><None></OPTION>
<OPTION VALUE="2">2</OPTION>
<OPTION VALUE="1">1</OPTION>
</SELECT>
</TD>
</TR>
</table>
我试过了$(".Q01:first").next('select').val();
但是它returnsundefined
编辑 - 我将 "input" 更改为 "select",我的错误。
答案编辑 - 感谢 Hello Cynogenic,我使用 "alert($('.Q01:first').next('td').find('select option:selected').val())
进一步缩小了我想要的范围,我从第一个 select 菜单中返回了 selected 选项.
首先,您有一个备用的 </TD>
标记,这意味着您的标记已损坏。
假设您删除错误标签,这将为您提供 select 元素:
$('.q1').next('td').find('select');
你必须一步步遍历文档。
next() 表示 "find the next element within this container, at this level, if it matches the specified selector"
find() 表示 "search the current element for children matching the specified selector"
alert($(".Q01:first" ).next('td').children().val());
检查下方 link :-)