<select id="Select1">
<option>1</option>
<option>2</option>
<option>3</option>
</select>
alert($("#Select1").val());
此代码是正确的并返回当前值。获取文本选择Runat =“服务器”
BUT
<select runat="server" id="Select1">
<option></option>
</select>
function parseXmlQuestion(xml)
{
$(xml).find("Question").each(function()
{
var value=$(this).find('Text').text()
$('#<%=Select1.ClientID %>').
append($("<option></option>").
attr("value",value).
text(value));
});
}
alert($('#<%=Select1.ClientID %>').val());
alert($('#<%=Select1.ClientID %> option:selected').val());
或
alert($('#<%=Select1.ClientID %>').text());
alert($('#<%=Select1.ClientID %> option:selected').val());
或
alert($('#<%=Select1.ClientID %>').html());
alert($('#<%=Select1.ClientID %> option:selected').val());
返回NU或不确定。
它实际上是追加'option'元素吗?当你在客户端(像FireBug那样的东西)检查它时,究竟发生了什么?第二个例子添加了更多的变量,而不仅仅是'runat =“server”'。 – David 2011-03-14 12:02:45
'<%= Select1.ClientID%>'应该返回什么? – Val 2011-03-14 12:08:19
你为什么重新发布这个问题? http://stackoverflow.com/questions/5297778/get-current-text-select – Andrew 2011-03-14 12:10:34