如何制作锚标签没有提及? [英] How to make an anchor tag refer to nothing?

查看:110
本文介绍了如何制作锚标签没有提及?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用jQuery,我需要使一些锚标签不执行任何操作。



我通常会这样写:

 < a href =#>连结< / a> 

然而,这指的是页面的顶部!

解决方案

如果你不想指向任何东西,你可能不应该使用< a> $)。

c $ c $< span> ),然后使用CSS对其进行设置:

 < span class =fake-linkid =fake-link-1>我是链接吗?< / span> 

.fake-link {
color:blue;
text-decoration:下划线;
光标:指针;
}

另外,假设你标记了这个问题jQuery你想附加一个点击事件手柄。如果是这样,只要做与上述相同的事情,然后使用类似下面的JavaScript:

  $('#fake-link点击(函数(){
/ *把你的代码放在这里* /
});


I use jQuery, I need to make some anchor tags perform no action.

I usually write it like this:

<a href="#">link</a>

However this refers to the top of the page!

解决方案

If you don't want to have it point to anything, you probably shouldn't be using the <a> (anchor) tag.

If you want something to look like a link but not act like a link, it's best to use the appropriate element (such as <span>) and then style it using CSS:

<span class="fake-link" id="fake-link-1">Am I a link?</span>

.fake-link {
    color: blue;
    text-decoration: underline;
    cursor: pointer;
}

Also, given that you tagged this question "jQuery", I am assuming that you want to attach a click event hander. If so, just do the same thing as above and then use something like the following JavaScript:

$('#fake-link-1').click(function() {
    /* put your code here */
});

这篇关于如何制作锚标签没有提及?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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