获取当前文本<select> </select>

时间:2011-03-14 11:11:39

标签: jquery-ui jquery jquery-selectors

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

此retrun&lt;%= sctFieldMain.ClientID%&gt;

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

这次重新定义

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

返回null

我喜欢Cureent Text。选择了

2 个答案:

答案 0 :(得分:4)

使用

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

EDITED

此外,您的问题会重复this onethis

答案 1 :(得分:0)

在html()函数之后你不需要半冒号而val不会返回你想要的html。

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

但是如果你有以下内容并想要值“示例”那么你应该使用val()

<option value="example">some test</option>