如何使锚点链接不可点击或被禁用? [英] How do you make an anchor link non-clickable or disabled?

查看:157
本文介绍了如何使锚点链接不可点击或被禁用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个锚点链接,一旦用户单击它,便要禁用它.或者,从文本周围删除定位标记,但绝对要保留文本.

I have an anchor link that I want to disable once the user clicks on it. Or, remove the anchor tag from around the text, but definitely keep the text.

<a href='' id='ThisLink'>some text</a>

通过添加.attr("disabled", "disabled");
,我可以轻松地通过按钮完成此操作 我已成功添加了disabled属性,但该链接仍可单击.
我真的不在乎文本是否带有下划线.

I can do this easily with a button by adding .attr("disabled", "disabled");
I successfully added the disabled property, but the link was still clickable.
I don't really care if the text is underlined or not.

有任何线索吗?

当您单击错误的音乐家时,它应该只添加错误",然后变得不可点击.
当您单击正确时,它应该添加"Awesome",然后禁用所有<a>标签.

When you click on the wrong musician, it should just add "Wrong" and then become unclickable.
When you click and you are correct, it should add "Awesome" and then disable all <a> tags.

推荐答案

我刚刚意识到您的要求(希望如此).这是一个丑陋的解决方案

I just realized what you were asking for(I hope). Here's an ugly solution

var preventClick = false;

$('#ThisLink').click(function(e) {
    $(this)
       .css('cursor', 'default')
       .css('text-decoration', 'none')

    if (!preventClick) {
        $(this).html($(this).html() + ' lalala');
    }

    preventClick = true;

    return false;
});

这篇关于如何使锚点链接不可点击或被禁用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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