我有两个函数需要执行,具体取决于在下拉列表中进行了哪些选择。处理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