Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 要添加提交按钮而不是输入键吗_Javascript_Html - Fatal编程技术网

Javascript 要添加提交按钮而不是输入键吗

Javascript 要添加提交按钮而不是输入键吗,javascript,html,Javascript,Html,我想添加一个提交按钮,而不是输入键 这是我的密码 <!DOCTYPE html> <html> <body> <input type="text" name="logsarchives" id="logsarchives" autocomplete="off" placeholder="Enter Console Command"

我想添加一个提交按钮,而不是输入键

这是我的密码

<!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>

函数重定向(ele){
如果(event.key=='Enter'){
如果(ele.value==='google')
window.location.href=https://google.com';
其他的
警报(“无效”);
}
}

从您的
中删除
onkeydown=“重定向(此)”
,并将提交按钮与包装表单一起添加:

<form method="post" action="https://where.you.want/to/process">
    <input type="text" name="logsarchives" id="logsarchives" autocomplete="off"  placeholder="Enter Console Command">
    <input type="submit" name="submit" value="submit>
</form>