HTML 表单 Enter press 是 keydown 而不是 keyup/keypress,从而启用垃圾邮件
当使用
<form>
<label>username
<input type="text" />
</label>
<label>password
<input type="text" />
</label>
<button type="submit">Login</button>
</form>
document.querySelector("form").addEventListener("submit", event => {
event.preventDefault();
console.log( "submitted" );
})
When using <form>
tags, it has a built-in behavior for enter key, which runs the submit.
They decided to make it using keydown, so it creates spam issues. For example if I had a form for a todo list, and i hold the enter key then it will spam create the same todo-item.
I want it to be keyup or keypress instead of keydown, I would still like enter key to submit rather than getting rid of it all together.
Using blur() also doesnt work since it doesnt focus on the button in the first place.
<form>
<label>username
<input type="text" />
</label>
<label>password
<input type="text" />
</label>
<button type="submit">Login</button>
</form>
document.querySelector("form").addEventListener("submit", event => {
event.preventDefault();
console.log( "submitted" );
})
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论