现在我有了这段代码:
$(".categories").change(function(){
var target = $('.categories option:selected').val();
if(target == "Career")
$(".subcat").css( "display","inherit" );
else if(target == "Life Style")
$(".subcat2").css( "display","inherit" );
else if(target == "Do It Yourself")
$(".subcat3").css( "display","inherit" );
else if (target == "Other")
$(".subcat4").css( "display","inherit" );
});
然而,当我选择任何类别时,它只返回值为“职业”,而不是其他任何东西,即使我选择其他选项。我该如何解决?
答案 0 :(得分:1)
尝试,
var target = $(this).val();
而不是
var target = $('.categories option:selected').val();