尽管该链接被禁用,但它仍然是可点击的。
<a href="/" disabled="disabled">123n</a>
如果它是禁用的,我可以使它不可点击吗?我应该使用JavaScript吗?
尽管该链接被禁用,但它仍然是可点击的。
<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/
其他回答
最好的答案总是最简单的。不需要任何编码。
如果(a)锚标记没有href属性,它只是一个超链接的占位符。所有浏览器均支持!
<a href="/">空闲web计数器</a><br /> <a "/">空闲web计数器</a> .
正确使用按钮和链接。
•按钮激活网页上的脚本功能(对话框,展开/折叠区域)。
•链接带你到另一个位置,无论是到不同的页面或同一页面上的不同位置。
如果你遵循这些规则,就不会出现任何需要禁用链接的情况。即使你让一个链接看起来视觉残疾和空白点击
<a href=“” ng-click=“Ctrl._isLinkActive &&$ctrl.gotoMyAwesomePage()”
你不会考虑可访问性,屏幕阅读器会将其视为链接,视力受损的人会一直好奇为什么链接不起作用。
我们不能直接禁用它,但我们可以这样做:
添加类型=“按钮”。 删除href=""属性。 添加disabled属性,这样它就会显示通过更改游标而禁用游标并使游标变暗。
PHP的例子:
<?php
if($status=="Approved"){
?>
<a type="button" class="btn btn-primary btn-xs" disabled> EDIT
</a>
<?php
}else{
?>
<a href="index.php" class="btn btn-primary btn-xs"> EDIT
</a>
<?php
}
?>
我有一个:
<a href="#">This is a disabled tag.</a>
希望对你有所帮助;)
适合我的变体:
<script>
function locker(){
if ($("a").hasClass("locked")) {
$("a").removeClass('locked').addClass('unlocked');
$("a").attr("onClick","return false");
} else {
$("a").css("onclick","true");
$("a").removeClass('unlocked').addClass('locked');
$("a").attr("onClick","");
}
}
</script>
<button onclick="locker()">unlock</button>
<a href="http://some.site.com" class="locked">
<div>
....
<div>
</a>