我很想知道如何从阵列中获取警报按摩撑条元素编号(巴西是6),而不是放置国家名称。我已经尝试了几种方法,但它没有用。
HTML:
<body>
<div></div>
</body>
Javascript:
var cleanCities = ["Argentina" , "Brazil", "Canada ", "Denmark"];
var visit = prompt("What is your city?");
var numLength = cleanCities.length;
var matchFound = false;
for (i=0; i<numLength ; i++)
if (visit === cleanCities[i]){
matchFound = true;
alert ("It is really a nice City")
break;
}
if (matchFound === false){
alert ("It is not in the List");
}
答案 0 :(得分:0)
首先,清理你的牙箍和标签:
var cleanCities = ["Argentina" , "Brazil", "Canada ", "Denmark"];
var visit = prompt("What is your city?");
var numLength = cleanCities.length;
var matchFound = false;
for (i=0; i<numLength ; i++) {
if (visit === cleanCities[i]) {
matchFound = true;
alert ("It is really a nice City")
break;
}
}
if (matchFound === false){
alert ("It is not in the List");
}
获取字符串的长度:
"Brazil".length
输出:6