そのため、年齢を入力した「アカウントの作成」フォームがあります。年齢要件を 16 に設定しています。私がやりたいことは、その人が 16 歳未満の場合にアラート メッセージを表示し、ユーザーがアラート ウィンドウの [OK] ボタンをクリックすると、インデックスに送り返すことです。ページ。これが私が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 も試しましたが、どちらも機能しません。これに関するヘルプは大歓迎です!