如何使用jQuery过滤DropDownList中的选项

我有2个DropDownList.first DropDownList有4个选项.Second DropDownList有20个选项。我想在第一个DropDownList中选择value = 1的选项时我在第二个DropDownList中显示所有元素,如果在第一个DropDownList中选择了value = 2的选项我展示了一些第二个DropDownList选项,等等。 我如何使用jQuery来做到这一点

编辑1)

代码是:

 
All Apples Orange Onion
Apple Style 1 Apple Style 2 Apple Style 3 Orange Style 1 Orange Style 2 Orange Style 3 Orange Style 4 Onion Style 1 Onion Style 2

你可以尝试这个jsFiddle: http : //jsfiddle.net/Chran/1/

HTML

 

JavaScript的

 var options = $("#DropDownList2").html(); $("#DropDownList1").change(function(e) { var text = $("#DropDownList1 :selected").text(); $("#DropDownList2").html(options); if(text == "All") return; $('#DropDownList2 :not([value^="' + text.substr(0, 3) + '"])').remove(); });​ 

根据ASP.Net Control Id,您必须更改Id。

希望这对你有所帮助。