2011-03-14 37 views
1

可能重複:
Get Text Select That Runat=「Server」獲取當前文本<選擇RUNAT = 「服務器」>

1:

HTML

<div id="dialog"> 
     <select id="Select1"> 
     <option>1</option> 
     <option>2</option> 
     <option>3</option> 
     </select> 
</div> 

腳本

$("#dialog").dialog({ "ok": function() { alert($("#Select1").val()); }); 

此代碼是正確的並返回當前值。

但卻但卻

2:

HTML

<div id="dialog"> 
     <select runat="server" id="Select1"> 
     <option></option> 
    </select> 
    </div > 

腳本

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()); 
}//Fill `Select1` 
//add correct information to `Select1` 


$("#dialog").dialog({ "ok": function() { `ALERT()` }); 

火 '確定' 功能:

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

返回null或undefined。

我喜歡獲取當前文本選擇。

我覺得問題在runat="server"<select>

+4

[Get Text Select Runat =「Server」](http://stackoverflow.com/questions/5298203/get-text-select-that-runat-server)和[獲取當前文本'