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>