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

2019-01-22 17:50发布

Should I put a Semicolon (;) when I use onclick=""

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

or

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

4条回答
干净又极端
2楼-- · 2019-01-22 18:20

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.

查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-01-22 18:23

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.

查看更多
ゆ 、 Hurt°
4楼-- · 2019-01-22 18:34

The semi-colon in this position, is valid, but not mandatory.

查看更多
做个烂人
5楼-- · 2019-01-22 18:40

As an optional semicolon, it's a matter of taste.

查看更多
登录 后发表回答