admin管理员组文章数量:1315369
Okay, so I am working on a weather application, and I wrote the following test code to verify that the user entered a valid state abbreviation:
var input = prompt("What state are you in?");
var lower = input.toLowerCase();
var categories = [
"ma",
"ny",
"ct",
"ri",
],
var found = $.inArray(lower, categories);
if (found > -1) {
alert("Cool!");
}
else {
alert("Oh no!");
}
But for some reason, it doesn't work.
Take a look: /
Does anyone know why this is? I probably just made a silly mistake, but any help would be greatly appreciated.
Okay, so I am working on a weather application, and I wrote the following test code to verify that the user entered a valid state abbreviation:
var input = prompt("What state are you in?");
var lower = input.toLowerCase();
var categories = [
"ma",
"ny",
"ct",
"ri",
],
var found = $.inArray(lower, categories);
if (found > -1) {
alert("Cool!");
}
else {
alert("Oh no!");
}
But for some reason, it doesn't work.
Take a look: http://jsfiddle/B24Bg/
Does anyone know why this is? I probably just made a silly mistake, but any help would be greatly appreciated.
Share Improve this question asked Jan 25, 2014 at 20:06 user2962388user2962388 3053 gold badges6 silver badges12 bronze badges 2- 1 extra ma at the end of array – stackErr Commented Jan 25, 2014 at 20:07
-
And another one before
var
. This fiddle doesn't pile... – Denys Séguret Commented Jan 25, 2014 at 20:08
1 Answer
Reset to default 6Check your console window in your browser, press F12, there are errors.
The ma after ] should be a semi-colon:
var input = prompt("What state are you in?");
var lower = input.toLowerCase();
var categories = [
"ma",
"ny",
"ct",
"ri"
];
var found = $.inArray(lower, categories);
if (found > -1) {
alert("Cool!");
}
else {
alert("Oh no!");
}
jsFiddle Demo
本文标签: javascriptJQuery inArray() not workingStack Overflow
版权声明:本文标题:javascript - JQuery .inArray() not working - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741975447a2408094.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论