onclick or onClick?(onclick 还是 onClick?)
问题描述
我以为在javascript中绑定点击事件是通过使用node.onclick
完成的,Chrome/Firefox似乎和我一致,但我看到它写成.onClick
这里 3 人 4 次,所以这不可能是错字,我怀疑这是巧合.
I thought that binding the click event in javascript is done by using node.onclick
, and Chrome/Firefox seem to agree with me, but I saw it written .onClick
here 4 times by 3 people, so it can't be a typo and I doubt that it's a coincidence.
那么,当 onClick
不起作用时,为什么人们还要写呢?
So, why are people writing onClick
when it does not work?
UPDATE:有两个很好的解释;我不知道其中哪一个最有道理,所以明天我将接受基于大众投票的答案.
UPDATE: There are two good explanations; I don't know which one of them is the most plausible, so I will accept the answer based on popular vote, tomorrow.
推荐答案
因为某些浏览器(取决于 DOCTYPE)可以容忍内联 onClick="something();"
属性...它似乎已经传播了一点,甚至在它不起作用的 JavaScript 问题中,因为大小写很重要.
Because some browsers (depending on the DOCTYPE) are tolerant of the inline onClick="something();"
attribute...it seems to have spread a bit, even into JavaScript questions where it doesn't work, since case matters.
另外,特别是对于stackoverflow...人们在问题中使用它...嗯,如果他们的代码有效,大多数时候他们不会问问题:)
Also, specifically to stackoverflow...people using it in questions...well, most of the time they wouldn't be asking a question if their code worked :)
这篇关于onclick 还是 onClick?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:onclick 还是 onClick?
基础教程推荐
- 直接将值设置为滑块 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01