简体   繁体   English

当我使用onclick =“”时,我应该放一个分号(;)

[英]Should I put a Semicolon (;) when I use onclick=“”

Should I put a Semicolon ( ; ) when I use onclick="" ? 当我使用onclick=""时,我应该放一个分号( ; )吗?

<p onclick="closeLightBox();">Click<p>

or: 要么:

<p onclick="closeLightBox()">Click<p>

此位置的分号有效,但不是强制性的。

It is good practice to include it, since if you decide to add other statements after the call, it is clear and easy to do so. 包含它是一种好习惯,因为如果您决定在通话后添加其他语句,则可以清楚且轻松地进行。 However, the code will run either way. 但是,代码将以任一方式运行。

I prefer a semicolon. 我更喜欢分号。 I know it is optional (as it is many times in JS), but I like to be uniform and it helps to alert the person that the statement is complete. 我知道它是可选的(因为它在JS中很多次),但我喜欢统一,它有助于提醒人们声明完整。

作为一个可选的分号,这是一个品味问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM