我正在使用带有 PHP 的 jQuery 脚本来根据下拉选择有条件地显示/隐藏表单字段。
脚本是:
//Hide the field initially
$("#hide1").hide();
//Show the text field only when the third option is chosen - this doesn't
$('#project-type').change(function() {
if ($("#project-type").val() == "Value 1") {
$("#hide1").show();
}
else {
$("#hide1").hide();
}
});
我希望能够向其中添加一个值数组,if ($("#project-type").val() == "Value 1")
因此如果有五个值,我希望某个字段显示何时选择值 1 和 3 而不是其他值。我尝试了一些方法,但它们都导致所有值都显示隐藏字段。
任何帮助表示赞赏。