“点击"与“点击"之间的区别然后点击 [英] Difference between "click" and onclick

查看:112
本文介绍了“点击"与“点击"之间的区别然后点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

点击进入有什么区别

document.getElementById("myBtn").addEventListener("click", displayDate);    

然后点击

<!DOCTYPE html>
<html>
<body>

<h1 onclick="this.innerHTML='Ooops!'">Click on this text!</h1>

</body>
</html> 

它们都被视为事件吗?为什么我们不能使用click而不是onclick,反之亦然?

Are they both considered as events? Why can't we use click instead of onclick and visce versa?

推荐答案

是的,它们都是事件,简单地讲是一样的,并且当为其分配处理程序 inline 时使用onclick使用事件侦听器进行分配时,推荐使用其他click(推荐的方法).

Yes, they are both events, simply put the same, and one use onclick when assign its handler inline, and the other click when assign using an event listener (which is the recommended way).

相反,您不能使用它们,因为这是必须完成的操作,否则它们将无法工作.

And you can't use them vice versa, as this is how it has to be done or they won't work.

有关MDN的更多信息:

Read more at MDN:

  • https://developer.mozilla.org/en-US/docs/Web/Events/click
  • https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Event_handlers

这篇关于“点击"与“点击"之间的区别然后点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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