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

问题描述 投票:1回答:3

我的网站有问题。如果输入框(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>
javascript html css
3个回答
1
投票

您只需在致电return false;后才需要window.location.href="martyna-lesniak.html";


0
投票

如果您有需要在其他文件夹中引用的HTML,而您需要将实际的html放在资源的路径(html)中,那么另一件事是有条件的,您可以将===放在一个字面上相等的对象


0
投票

尝试一下

<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>
© www.soinside.com 2019 - 2024. All rights reserved.