给定一个像这样的 jQuery 元素:
$(selectElt)
如何访问第一个选项?请注意,我对给定选择菜单 ID 的选择器不感兴趣,例如
$('#selectmenu1 option:first')
我得到的是选择元素本身,$(selectElt)
,我需要从中选择第一个选项元素。
最佳答案
你可以试试
$(selectElt).children('option').eq(0)
或
$(selectElt).children('option:first')
或
$(selectElt).children('option').first()
正如罗里·麦克罗森所说
$('option:first',selectElt)
还有最后一个
$(selectElt).children('option').filter(':first')
关于jquery - 在 jQuery 中,给定一个选择菜单元素,如何访问第一个选项元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27987965/