问题描述
这好像不是我没有用谷歌搜索过……但是我还是不明白何时使用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
事件.
onsubmit
事件.该事件的起源有时可以追溯到onclick
(如单击提交"按钮),但也可以来自键盘事件(如按).
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 ).
这意味着在表单上的提交"按钮上使用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有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!