get current text <select>

                 <select runat="server" id="sctFieldMain">
                 <option></option>
                   </select>

Script

   $(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());

this retrun <%=sctFieldMain.ClientID %>

or

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

this retrun undefined

or

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

return null

i like get Cureent Text. that selected


Use

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

EDITED

Also your question duplicates this one and this.


You don't need the semi colon after the html() function and val does not return the html which is what your looking for.

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

However if you had the following and wanted the value "Example" then you should use val()

<option value="example">some test</option>
链接地址: http://www.djcxy.com/p/83078.html

上一篇: 如何使用jQuery获取html <option>标记的内容

下一篇: 获取当前文本<select>