所以我有一个带有年龄输入的“创建帐户”表单。我将年龄要求设置为 16。我想要做的是,如果此人未满 16 岁,它会发出警报消息,然后当用户单击警报窗口上的“确定”按钮时,它会将其发送回索引页。这是我的 JS 代码:
if (age == null || age == "")
{
alert("Please enter your age to continue.");
return false;
}
else if (age == isNaN(age))
{
alert("Age input was not a number!\nPlease enter your age to continue.");
return false;
}
else if (age < 16)
{
alert("You are not old enough to have an account.\n If you have concerns or questions about our age policy please send them to ghost565xster@gmail.com.");
return false;
}
基本上,当它运行最后一个“else if”语句并发现输入小于 16 时,我希望它在显示警报消息后将用户重定向到 index.html(主页)页面。
我试过使用:
else if (age < 16)
{
alert("You are not old enough to have an account.\n If you have concerns or questions about our age policy please send them to ghost565xster@gmail.com.");
location.assign("index.html");
return false;
}
我也尝试过 location.href 但都没有工作。对此的任何帮助将不胜感激!