这是我的第二天编码,所以如果我不知道如何正确解释或基本解决方法,请原谅我。

我正在尝试在网站上复制控制台界面,并且我希望输入框仅在得到特定输入的情况下才重定向到特定链接。我还希望它根本不重定向,并且在给出无效提示时给出一条消息。
到目前为止,我输入框的代码是

  <form action="backlog">
    <label for="fname">
    <input type="text" name="logsarchives" id="logsarchives" autocomplete="off"  placeholder="Enter Console Command">
    </form>


到目前为止,可以查看代码here,而可以查看网站here
谢谢您阅读此篇!

最佳答案

因此,您需要一些JavaScript来处理这种情况。同样,没有适当的关闭目的,甚至没有关闭标签,只是使用了不必要数量的标签

<!DOCTYPE html>
<html>
    <body>
        <input type="text" name="logsarchives" id="logsarchives" autocomplete="off"  placeholder="Enter Console Command" onkeydown="redirect(this)">
    </body>
    <script>
        function redirect(ele) {
            if(event.key === 'Enter') {
                if(ele.value === 'google')
                     window.location.href = 'https://google.com';
                else
                    alert("Invalid");
            }
        }
    </script>
</html>

关于javascript - 给定特定输入时如何重定向到特定页面,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51563379/

10-11 22:32
查看更多