且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在下拉列表上应用列表过滤器

更新时间:2023-12-01 15:30:46

您已分配了名为Dat的变量,然后使用if(Data == "Yes")

You've assigned your variable called Dat and are then checking it's value using if(Data == "Yes")

在这种情况下,使用switch语句可能根本不分配变量会更容易

It'd probably be easier not to assign variable at all in this case, by using a switch statement

$('#a').live('change',function()
{
switch($(this).find("option:selected").text()) {
  case "Yes":
    $('#b').find("option[value='1']").show();
    $('#b').find("option[value='2']").hide();
    $('#b').find("option[value='3']").hide();
    break;

  case "No":
    $('#b').find("option[value='3']").hide();
    $('#b').find("option[value='1']").show();
    $('#b').find("option[value='2']").hide();
    break;

  case "N.A.":
    $('#b').find("option[value='1']").hide();
    $('#b').find("option[value='2']").hide();
    $('#b').find("option[value='3']").show();
}
});