0

そのため、年齢を入力した「アカウントの作成」フォームがあります。年齢要件を 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 も試しましたが、どちらも機能しません。これに関するヘルプは大歓迎です!

4

5 に答える 5

1

locationプロパティに新しい値を割り当てるだけです。location = "index.html"

于 2013-09-24T10:13:56.530 に答える
0

これを使って:

 window.location.href = "your location";
于 2013-09-24T10:14:31.433 に答える
-1

できるだけ簡単に:

window.location = "http://www.google.com/"
于 2013-09-24T10:15:20.290 に答える