2011-03-14 43 views
2
    <select runat="server" id="sctFieldMain"> 
       <option></option> 
        </select> 

脚本获取当前文本<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()); 

这retrun <%= sctFieldMain.ClientID%>

alert($("#<%=sctFieldMain.ClientID %> option:selected").val()); 

这retrun不确定

alert($("#<%=sctFieldMain.ClientID %> option:selected").html()); 

返回NULL

我喜欢得到Cureent文本。所选

+0

你不需要分号在你VAL结束()或文本()BTW – Andrew 2011-03-14 11:20:14

+0

您是否尝试过:$('#<%= sctFieldMain.ClientID%>')。val(); – Andrew 2011-03-14 11:26:49

+0

return'' – ashkufaraz 2011-03-14 11:31:29

回答

4

使用

alert($("#<%=sctFieldMain.ClientID %> option:selected").html()); 

EDITED

而且你的问题复制this onethis

+0

.html()返回null。 – ashkufaraz 2011-03-14 11:22:32

+1

适合我! http://jsfiddle.net/3RLve/ – CoolEsh 2011-03-14 11:26:47

+0

但这段代码是