是否有一种方法禁用链接使用CSS?

我有一个名为current-page的类,并希望禁用该类的链接,以便在单击它们时不发生任何操作。


当前回答

演示 试试这个

$('html').on('click', 'a.Link', function(event){
    event.preventDefault();
});

其他回答

你可以将href属性设置为javascript:void(0):

.disabled { /*禁用链接样式*/ 颜色:黑色; } <a class="disabled" href="javascript:void(0)“链接> < / >

Bootstrap禁用链接

<a href="#" class="btn btn-primary btn-lg disabled" role="button">Primary link</a>

<a href="#" class="btn btn-default btn-lg disabled" role="button">Link</a>

Bootstrap禁用按钮,但它看起来像链接

<button type="button" class="btn btn-link">Link</button>

指针事件属性允许控制HTML元素如何 响应鼠标/触摸事件-包括CSS悬停/活动状态, 在JavaScript中点击/点击事件,以及光标是否在 可见。

这不是禁用链接的唯一方法,但这是一个很好的CSS方法,适用于Internet Explorer 10(及更高版本)和所有新浏览器:

.current-page { pointer-events:没有; 颜色:灰色; } <a href="#" class="current-page">该链接被禁用</a> .

在HTML上应用下面的类。

.avoid-clicks {
  pointer-events: none;
}

试试这个:

<style>
    .btn-disable {
        display: inline-block;
        pointer-events: none;
    }
</style>