【发布时间】:2015-10-30 07:48:30
【问题描述】:
我在这里缺少什么?这个脚本对我来说很合适。
但由于某种原因,当我向它发送 02897 的邮政编码(或任何应该是罗德岛的地方)时,它会返回新罕布什尔州。除了 Javascript 开发人员可能有的政治信仰(当然大多数人宁愿住在新罕布什尔州而不是罗德岛州),为什么这个脚本不起作用?
新泽西州和阿拉巴马州工作正常。为什么罗德岛得不到爱情?
function getState(zip) {
var thiszip = zip; // parseInt(zip);
if (thiszip >= 35000 && thiszip <= 36999) {
thisst = 'AL';
thisstate = "Alabama";
}
else if (thiszip >= 03000 && thiszip <= 03899) {
thisst = 'NH';
thisstate = "New Hampshire";
}
else if (thiszip >= 07000 && thiszip <= 08999) {
thisst = 'NJ';
thisstate = "New Jersey";
}
else if (thiszip >= 02800 && thiszip <= 02999) {
thisst = 'RI';
thisstate = "Rhode Island";
}
else {
thisst = 'none';
}
return thisst;
}
【问题讨论】:
-
请添加一个jsfiddle
-
JavaScript 会忽略 zip 前面的 0
标签: javascript comparison-operators