簡體   English   中英

JavaScript window.location.href 在本地主機中不起作用

[英]JavaScript window.location.href not working in localhost

我的網站有問題。 當輸入框(id textbox_text)中有“333”時,網站應該重定向到指定的url,但沒有任何反應。 問題出在哪里?

    <script>
            function IsEmpty()
            {
            if(document.forms['frm'].textbox_text.value == "333")
             {
                window.location.href="martyna-lesniak.html";
            }
            else 
            {
                alert("Nieprawidłowe hasło!");
            }
        }
    </script>
    <div class="container">
        <form name="frm">
            <input type="password" name="password1" class="password-input" id="textbox_text" placeholder="Wpisz hasło">
            <input type="submit" name="submit" onclick="return IsEmpty();" value="Wysyłaj" class="button-input" />
        </form>
    </div>

你只需要return false; 在您致電window.location.href="martyna-lesniak.html"; .

如果您有 HTML ,您需要在其他文件夾中引用實際的 html 您需要放置資源的路徑(html),另一件事是在條件中,您可以放置 === 以使文字等於 ZA8CFDE6331BD49EB2AC96F8966

嘗試這個

<script>
        function IsEmpty()
        {
        if(document.forms['frm'].textbox_text.value == "333")
         {

            window.location.href="martyna-lesniak.html";
            return false;
        }
        else 
        {
            alert("Nieprawidłowe hasło!");
        }
    }
</script>
<div class="container">
    <form name="frm">
        <input type="password" name="password1" class="password-input" id="textbox_text" placeholder="Wpisz hasło">
        <input type="submit" name="submit" onclick="return IsEmpty();" value="Wysyłaj" class="button-input" />
    </form>
</div>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM