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

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

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


当前回答

在我的情况下,我使用

<a href="/" onClick={e => e.preventDefault()}>

其他回答

您可以在<a>标记上模拟禁用属性。

<a href=" Link .html" disabled="">Link</a> .html

a[disabled] {
   pointer-events: none;
   cursor: default;
}

在我的情况下,我使用

<a href="/" onClick={e => e.preventDefault()}>

如果你需要用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/

我们不能直接禁用它,但我们可以这样做:

添加类型=“按钮”。 删除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="javascript:void(0)" style="cursor: default;">123n</a>