我有兩個函數需要執行,具體取決於在下拉列表中進行了哪些選擇。處理jquery中的多個事件
例如,如果
Dropdownlist1
值是「第一」,則禁用Dropdownlist2
和執行Function1
如果Dropdownlist1
值是「第二」,那麼啓用Dropdownlist2
並且如果「第三」被選擇爲Dropdownlist2
值執行Function2
。我在Document ready事件中嘗試了一個常規if語句,但無法實現上面我想要的。
這是我到目前爲止有:
形式:
<th>
Dropdown List 1
</th>
<td>
<%= Html.Telerik().DropDownList().Name("DropDownList1")
.HtmlAttributes(new { @id = "DropDownList1" })
.Items(items => {
items.Add().Text("").Value("");
items.Add().Text("New").Value("First");
items.Add().Text("Existing").Value("Second");
})%>
</td>
<th>
Dropdown List 2
</th>
<td>
<%= Html.Telerik().DropDownList().Name("DropDownList2")
.HtmlAttributes(new { @id = "DropDownList2" })
.Items(items => {
items.Add().Text("").Value("");
items.Add().Text("Three").Value("Three");
})%>
</td>
JQuery的:
$(function() {
$("#Dropdownlist1").focusout(func1);
});
function func1() {
$("#Dropdownlist1").focusout(function(){
if($("#Dropdownlist1").val() == "First"){
$("#Dropdownlist2").attr('disabled','disabled')
Function1()
}
else if ($("#Dropdownlist1").val() == "Second"){
$("#Dropdownlist2").attr('disabled','')
$("#Dropdownlist2").focusout(function(){Function2()})
}
});
}
如果您可以發佈您嘗試過的任何HTML/Javascript/jQuery代碼,這將有所幫助。 – Chase
@Chase我上面更新了我的問題 – user793468
我在下面添加了一個答案,但如果它沒有完全回答問題,請告訴我,我會盡我所能修復它/幫助。謝謝 – Chase