|
我需要一個用于ASP.NET項目的組合框,所以我決定使用Ajax Control Toolkit組合框(http://www./AJAX/AjaxControlToolkit/Samples/ComboBox/ComboBox.aspx).
我不想使用回發(fā),因為我不想重新加載頁面,但我需要知道文本框中的文本何時更改,以便我可以調(diào)用服務器來保留新的列表項.
我很好奇如何將onchange或onblur事件綁定到此組合框使用的輸入框.
這是我的頁面:
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %>
<cc1:ComboBox ID="PlantDropDown" runat="server" OnInit="PlantDropDown_Init" DropDownStyle="DropDown"
AutoCompleteMode="SuggestAppend"
ItemInsertLocation="OrdinalText" AutoPostBack="false">
</cc1:ComboBox>
更新:我嘗試使用該建議,我收到此錯誤:
$find("PlantDropDown") is null
[Break on this error] $find('PlantDropDown').add_propertyChanged(function(sender, e) {\r\n
我在javascript方面使用jQuery,順便說一句,如果有幫助的話.
最后更新: 我得到了它的工作,感謝crescentfresh的幫助,最后我在我的.aspx文件中有這個:
<input type="hidden" id="PlantDropDownID" value="<%= PlantDropDown.ClientID %>" />
這是在我的javascript文件中,因為我不在我的.aspx文件中推送javascript:
elem = document.getElementById('PlantDropDownID');
$find(elem.value).add_propertyChanged(function(sender, e) {
if (e.get_propertyName() == 'selectedIndex') {
var newValue = sender.get_textBoxControl().value;
}
})
解決方法: 我相信你應該綁定到“propertyChanged”事件并檢查“selectedIndex”屬性的更改:
$find('PlantDropDown').add_propertyChanged(function(sender, e) {
if (e.get_propertyName() == 'selectedIndex') {
var newValue = sender.get_textBoxControl().value;
// persist selected value here...
}
})
與通常的警告約.NET control ids in the client.
api并不容易,這是肯定的.例如,沒有.get_value()方法,這將是很好的,而不必通過嵌入的文本框控件.
編輯:
> $find(“PlantDropDown”)為空
確保使用正確的ID.請參閱.NET control ids in the client.要獲得參考,您可能需要執(zhí)行以下操作:
$find('<%= PlantDropDown.ClientID %>')
>我在javascript方面使用jQuery
這沒有任何意義. 來源:https://www./content-1-349851.html
|