【发布时间】:2011-03-14 11:11:38
【问题描述】:
<select runat="server" id="sctFieldMain">
<option></option>
</select>
脚本
$(xml).find("FieldMain").each(function()
{
var value=$(this).find('Title').text()
$('#<%=sctFieldMain.ClientID %>').
append($("<option></option>").
attr("value",value).
text(value));
});
alert($("#<%=sctFieldMain.ClientID %> option:selected").text());
此返回
或
alert($("#<%=sctFieldMain.ClientID %> option:selected").val());
这个返回未定义
或
alert($("#<%=sctFieldMain.ClientID %> option:selected").html());
返回空值
我喜欢获取当前文本。被选中的
【问题讨论】:
-
你不需要在你的 val() 或 text() BTW 末尾的分号
-
你试过了吗:$('#').val();
-
可能是个愚蠢的问题,但是您的 js 是否有可能在外部
.js文件中而不是在页面上?
标签: jquery-ui jquery jquery-selectors