尽管该链接被禁用,但它仍然是可点击的。
<a href="/" disabled="disabled">123n</a>
如果它是禁用的,我可以使它不可点击吗?我应该使用JavaScript吗?
尽管该链接被禁用,但它仍然是可点击的。
<a href="/" disabled="disabled">123n</a>
如果它是禁用的,我可以使它不可点击吗?我应该使用JavaScript吗?
当前回答
超链接没有disabled属性。如果你不想要某些东西被链接,那么你需要移除<a>标签。
或者,你可以删除它的href属性-尽管这有其他的用户体验和可访问性问题,在下面的评论中指出,所以不建议。
其他回答
如果你需要用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/
$(document).ready(function() {
$('a').click(function(e) {
e.preventDefault();
});
});
您需要删除<a>标记来摆脱这个。
或者试着使用:-
<a href="/" onclick="return false;">123n</a>
您可以在<a>标记上模拟禁用属性。
<a href=" Link .html" disabled="">Link</a> .html
a[disabled] {
pointer-events: none;
cursor: default;
}
当您将鼠标移到href标签上时,href标签中的任何内容都将显示在浏览器窗口的左下角。
我个人认为像javascript:void(0)这样的东西显示给用户是可怕的。
相反,关闭href,使用jQuery/其他工具,添加一个样式规则(如果你仍然需要它看起来像一个链接):
a {
cursor:pointer;
}