我是新来的jQuery,但这是我想要做的。jQuery比较提交表单前选择字段值与数组
我有一个多选择字段命名城市和Zip形式,
我试图让这个选择字段的值,并将其与城市的名单上有,如果发现任何匹配的jQuery将使用这些值更新名为city的隐藏文本字段的值,然后提交表单。如果找不到匹配,他们将被重定向到不同的网站。
与邮政编码相同的东西,它会从同一字段获取邮政编码,并查看它是否与列表中的任何邮政编码匹配。如果是,则更新邮政编码隐藏字段,如果没有,则将其重定向到另一个网站。
这是我现在的代码,它不工作。
$("#front-form").submit(function(event) {
// Getting the values from the HTML select field
var CityandZip = $("#citynzip").val();
//Comparing the values with the cities list
if (CityandZip === "City 1" || "City 2" || "City 3") {
//Updaing the hidden field and submitting
$("#HiddenCityField").val(CityandZip);
//Comparing the values with the ZIP code list
} else if (CityandZip === "11111" || "11112" || "11113") {
//Updating the hidden ZIP code field
$("#HiddenZipField").val(CityandZip);
} else {
//Redircting to a new site
window.location.href = "http://www. redirecttowebsite.com";
}
});
任何帮助将不胜感激,并感谢先进。
你的||是错的(CityandZip ===“11111”|| CityandZip ===“11112”|| CityandZip ===“11113”)使用调试器,你会很容易地发现这种错误。 – 2013-02-19 20:56:10