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>

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.

Any clue?

当你点击错误的音乐家时,它应该只添加"错误",然后变得不可点击

推荐答案

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

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;
});

Jquery相关问答推荐

TinyMCE不保存区块报价

使用带有 bootstrap 验证的 Ajax 函数时出现问题

在 jQuery 事件中控制this的值

Javascript 仅打印 iframe 内容

如何计算具有相同类的元素数量?

用jquery查找div底部的位置

如何通过 Select 插件使用 jQuery 验证?

lodash debounce 在匿名函数中不起作用

使用跨域帖子发送凭据?

jQuery - 用 DIV 跟随光标

根据弹出框相对于窗口边缘的 X 位置更改 Bootstrap 弹出框的位置?

为不同的 node 类型配置jstree右键上下文菜单

Rails 5:如何将 $(document).ready() 与 turbo-links 一起使用

父母的jQuery父母

jquery可排序占位符高度问题

如何使用 jQuery 取消设置元素的 CSS 属性?

jQuery empty() 与 remove()

如何在调用 Ajax 等异步调用时让代码等待

Jquery Select 所有具有 $jquery.data() 的元素

如何在 jQuery 中取消绑定悬停?