我想添加一个Submit按钮而不是Enter键
这是我的代码
<!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>
答案 0 :(得分:0)
从onkeydown="redirect(this)"
中删除<input>
,然后添加提交按钮和包装表单:
<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>