这是在链接上调用JavaScript函数的最佳方式 [英] Which is the best way to call a javascript function on a link

查看:92
本文介绍了这是在链接上调用JavaScript函数的最佳方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想添加一些链接到我的某个网站,但这些链接将调用一个javascript函数并且不会加下划线,我还希望将光标更改为标准指针。这是做这件事的最好方法,为什么?



现在我可以想到两个问题:

< a href =javascript:someFunction()style =text-decoration:none> LINK< / a>



< span onClick =someFunction(); style =cursor:pointer;> LINK< / span>



您认为哪一个更好? b $ b

解决方案

因为这不是一个真正的链接(功能或视觉),您应该坚持使用< span> ; (或< div> 如果您想要块级元素)。


I want to add some links to some website of mine, but these links will call a javascript function and will not be underlined, also I want the cursor to be changed to a standard pointer. Which is the best way of doing it and why?

Right now I can think of two aproaches:

<a href="javascript:someFunction()" style="text-decoration:none">LINK</a>

or

<span onClick="someFunction();" style="cursor: pointer;">LINK</span>

Which one do you think is better?

解决方案

Since this isn't really going to be a link (functionally or visually) you should stick with a <span> (or <div> if you want a block level element).

这篇关于这是在链接上调用JavaScript函数的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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