onclick 和 onsubmit 有什么区别? [英] Whats the difference between onclick and onsubmit?

查看:22
本文介绍了onclick 和 onsubmit 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这不是我没有google过...但是我还是不明白什么时候使用onsubmit,什么时候使用onclick?

It's not like I haven't googled it... But still I couldn't understand when onsubmit is used and when onclick is used?

推荐答案

它们是两个完全独立的事件.

They're two completely separate events.

onclick 事件在用户使用鼠标点击某物时触发.

onclick events fire when the user uses the mouse to click on something.

onsubmit 事件在提交表单时触发.此事件的起源有时可以追溯到 onclick(如单击提交"按钮),但它也可能来自键盘事件(如按 enter).

onsubmit events fire when a form is submitted. The origin of this event can sometimes be traced back to an onclick (like clicking the "submit" button) but it can also come from a keyboard event (like pressing enter).

这意味着在表单上的提交按钮上使用 onclick 可能会错过表单上的 onsubmit 会捕获的某些情况.

This implies that using onclick on a submit button on a form might miss some cases that an onsubmit on the form would catch.

还有许多其他类型的事件,例如:onload 用于加载脚本或图像等资源,onkeydown 用于检测键盘上的按键.

There are many other kinds of events such as: onload for loading resources such as scripts or images and onkeydown for detecting key presses on the keyboard.

这篇关于onclick 和 onsubmit 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆