jquery 在下拉菜单中查找所选项目的值
我有一个下拉列表,显示选择标记中的值,我通常只使用 $('#ID').val() 来获取值,但 ID 要么未知,要么是动态添加的行。
在关闭选择标签之后,我有一个正在使用的 jquery ui 图标,单击该图标将捕获当前选择的下拉选项的值(该值将被复制到其他选择列表)。这段代码循环,所以我知道我需要使用某种 .find() 或 .parent() 或类似的东西,但我还没有理解。
这是源代码:
<tr>
<th class="form"><label>SI Contact</label></th>
<td id="name_29805"><div style="float: left;">
<select name="contactsbcuid" id="contactsbcuid_29805" sid="29805" ordr="1">
<option value="userID1234">Doe, John</option>
<option value="userID1235">Doe, Jane</option>
...
<option value="userID1236">Smith, David</option>
</select>
<input name="orig_contactsbcuid" id="orig_contactsbcuid_29805" value="userID1235" sid="29805" ordr="1" type="hidden">
</div>
<div style="float: right;"><span class="ui-icon ui-icon-copy vtip" onClick="CopyDown('contactsbcuid',1)" id="select_contactsbcuid_29805" title="Copy the selected value down the list." style="float: right;"></span></div></td>
I have a drop down list displaying values in a select tag that I would normally just use $('#ID').val() to obtain the value but the ID is either unknown or a dynamically added row.
Following the closing select tag, I have an jquery ui icon I'm using that when clicked will capture the value of drop down option currently selected (this value will be replicated to the other select lists). This bit of code loops so I know I'll need to use some sort of .find() or .parent() or something along those lines which is still not sunk in with me yet.
Here is the source code:
<tr>
<th class="form"><label>SI Contact</label></th>
<td id="name_29805"><div style="float: left;">
<select name="contactsbcuid" id="contactsbcuid_29805" sid="29805" ordr="1">
<option value="userID1234">Doe, John</option>
<option value="userID1235">Doe, Jane</option>
...
<option value="userID1236">Smith, David</option>
</select>
<input name="orig_contactsbcuid" id="orig_contactsbcuid_29805" value="userID1235" sid="29805" ordr="1" type="hidden">
</div>
<div style="float: right;"><span class="ui-icon ui-icon-copy vtip" onClick="CopyDown('contactsbcuid',1)" id="select_contactsbcuid_29805" title="Copy the selected value down the list." style="float: right;"></span></div></td>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来表格单元格中只有一个选择。
因此,找到“td”就足够了,找到它后就可以搜索选择。
It looks like there is only a single select in the tablecell.
So it should be sufficient to find the 'td' and when you've found it search for the select.
这 jsFiddle 是您真正要找的吗?
jQuery:
Is this jsFiddle what you are essentially looking for?
jQuery: