1

変数 money が 100 に等しい場合、JavaScript コードを Index.html ページにリダイレクトしようとしています。html フォーム コードは次のとおりです。

<form id = "form"  action = "">
    <h1> Enter the amount of money you would like to spend on your next trip. </h1><br>

            <div class="input-group">
              <span class="input-group-addon">$</span>
              <input type="text" name="money" class="form-control">

            </div>
            <br>
            <button type="submit" class="btn btn-default" onclick = "MoneyForTrip()">Show Trips</button>

            </form>

そしてJavaScript:

var money;

function MoneyForTrip()
{
money = parseInt(
        document.getElementById('form').money.value);

    if (money == 100)
    {
        window.location="Index.html";
    }


    else
    {
        window.alert("Enter another number"); 
    }

}

お金が100に等しい場合、Index.htmlにリダイレクトする方法を教えてください。

4

3 に答える 3

1

これを試して。

window.location.replace("Index.html")

また

window.location.href = "Index.html"

この Stack Answer もご覧ください。

于 2013-11-13T00:51:24.787 に答える
0

試す
<input type="text" name="money" id="moneyfortrip" class="form-control">

var money;

function MoneyForTrip()
{
money = parseInt(
        document.getElementById('moneyfortrip').value);

    if (money == 100)
    {
        window.location="Index.html";
    }


    else
    {
        window.alert("Enter another number"); 
    }

}
于 2013-11-13T00:52:23.487 に答える