尽管该链接被禁用,但它仍然是可点击的。

<a href="/" disabled="disabled">123n</a>

如果它是禁用的,我可以使它不可点击吗?我应该使用JavaScript吗?


当前回答

如果你需要用Javascript禁用laravel上的链接,这是我的解决方案:

链接(blade.php):

<a href='/link/to/path' class='btn btn-primary mt-3' onclick='disableLink(this)'>Confirmar</a>

. css文件

.isDisabled {
    cursor: not-allowed;
    opacity: 0.5;
}

a[aria-disabled="true"] {
    color: currentColor;
    display: inline-block; /* For IE11/ MS Edge bug */
    pointer-events: none;
    text-decoration: none;
}

.js文件

function disableLink(link) {
    // 1. Add isDisabled class to parent element
    link.parentElement.classList.add('isDisabled');
    // 2. Store href so we can add it later
    link.setAttribute('data-href', link.href);
    // 3. Set aria-disabled to 'true'
    link.setAttribute('aria-disabled', 'true');
}

function enableLink(link) {
    // 1. Remove 'isDisabled' class from parent span
    link.parentElement.classList.remove('isDisabled');
    // 2. Set href
    link.href = link.getAttribute('data-href');
    // 3. Remove 'aria-disabled', better than setting to false
    link.removeAttribute('aria-disabled');
}

参考:https://css-tricks.com/how-to-disable-links/

其他回答

超链接没有disabled属性。如果你不想要某些东西被链接,那么你需要移除<a>标签。

或者,你可以删除它的href属性-尽管这有其他的用户体验和可访问性问题,在下面的评论中指出,所以不建议。

$(document).ready(function() {
   $('a').click(function(e) {
     e.preventDefault();
  });
});

最好的答案总是最简单的。不需要任何编码。

如果(a)锚标记没有href属性,它只是一个超链接的占位符。所有浏览器均支持!

<a href="/">空闲web计数器</a><br /> <a "/">空闲web计数器</a> .

你可以使用下面的代码在运行时使用javascript禁用链接

$ (' .page-link ') . css(“pointer-events”、“没有”);

你可以使用:

<a href="/" onclick="return false;">123n</a>