简体   繁体   English

HTML5 在锚点中使用 Javascript 的正确方法是什么?

[英]What is the correct way in HTML5 to use Javascript in anchors?

Simple question, what is the correct way in HTML5?简单的问题,HTML5 中的正确方法是什么?

   1st: <a href="javascript:func('something')">Something</a>    
   2nd: <a href="javascript:void(0)" onclick="func('something')">Something</a>
   3rd: <a href="#" onclick="func('something')">Something</a><!-- probably bad approach -->
   4th: <a onclick="func('something')">Something</a>

I don't want to or can't use event listener because it is an EJS template and the 'something' are from serveride (NodeJS) variable.我不想或不能使用事件侦听器,因为它是一个 EJS 模板,而“某些东西”来自服务器端 (NodeJS) 变量。

I went with the first one.我和第一个一起去了。 I have talked it about a web specialist he said there is no correct way but the most "liked" option is the event listener but since it is not an option for me because of the serverside ejs render i can choose any of them.我谈到了一位 web 专家,他说没有正确的方法,但最“喜欢”的选项是事件侦听器,但由于服务器端 ejs 渲染,它对我来说不是一个选项,我可以选择其中任何一个。

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

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