URL重定向Javascript?我试图重定向一个带有http://的输入网址,并提示直到找到http://,如果找到它,它将直接转到输入的网站。
这是我目前的代码:
function enter() {
var keepGoing = true;
var email;
while (keepGoing) {
keepGoing = false
email = prompt("Please Enter Website Address");
// Website Address validation to see if it has http://
if (email.indexOf('http://') === -1) {
alert("Not valid Web Address");
keepGoing = true;
}
// if nothing was entered
else if (email == '') {
var email = prompt("Please Enter Valid Web Address");
}
}
}
keepGoing
变量相当不必要。 - JJJemail.indexOf('http://') === -1
应该改为email.indexOf('http://') !=0
,因为你必须验证 http:// 是否是网站地址的第一部分。 - Iswanto San