【发布时间】:2010-05-24 19:09:42
【问题描述】:
如果列表是动态创建的,我如何获取可选列表中项目的“id”?
<ul id="selectable">
<li id='1'>..</li>
.
.
<li...
</ul>
我尝试了var num = $('#selecable :selected').attr( "option" , 'id' );,但只得到 [object Object]...
什么是正确的方法?
【问题讨论】:
-
ID 不能是数字,或者不能以数字开头,请确保您的 ID 具有某种前缀,以便它们有效。
-
@Nick Craver 好点,当我看到那个时我错过了。
-
你的“#selecable”有错别字
-
$('.ui-selected', this ).attr('id'); -
你可以使用这个方法。 stackoverflow.com/questions/15621111/… ----------------------------------------------- -------------------------
标签: jquery user-interface get selectable