[attr.disabled]="true" 在锚标签中不起作用
[attr.disabled]="true" does not working in anchor tag
为什么 [attr.disabled]="true"
在锚标签中不起作用?
组件:
this.isHold=true;
html:
<a (click)="showDialogToHold()" href="Javascript:void(0);" class="a-l2-link
img-space" icon="fa-angle-right" [attr.disabled]="isHold">Hold</a>
我也试过[disabled]="isHold"
。但是 [disabled]
不支持锚标签。它抛出与
有关的错误 Can't bind to 'disabled' since it isn't a known property of 'a'
html 中的超链接没有禁用属性。参考https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a。因此,您可以使用 css 来实现这一点。
CSS 代码:
text-decoration:none;
cursor:default;
color:grey;
pointer-events:none;
尝试:
<a (click)="showDialogToHold()" href="Javascript:void(0);" class="a-l2-link
img-space" icon="fa-angle-right" disabled={{isHold}}>Hold</a>
.disabled {
pointer-events: none !important;
cursor: default;
}
<a (click)="showDialogToHold()" href="Javascript:void(0);" class="a-l2-link
img-space" icon="fa-angle-right" [ngStyle]="{ 'disabled ': isHold }">Hold</a>
为什么 [attr.disabled]="true"
在锚标签中不起作用?
组件:
this.isHold=true;
html:
<a (click)="showDialogToHold()" href="Javascript:void(0);" class="a-l2-link
img-space" icon="fa-angle-right" [attr.disabled]="isHold">Hold</a>
我也试过[disabled]="isHold"
。但是 [disabled]
不支持锚标签。它抛出与
Can't bind to 'disabled' since it isn't a known property of 'a'
html 中的超链接没有禁用属性。参考https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a。因此,您可以使用 css 来实现这一点。
CSS 代码:
text-decoration:none;
cursor:default;
color:grey;
pointer-events:none;
尝试:
<a (click)="showDialogToHold()" href="Javascript:void(0);" class="a-l2-link
img-space" icon="fa-angle-right" disabled={{isHold}}>Hold</a>
.disabled {
pointer-events: none !important;
cursor: default;
}
<a (click)="showDialogToHold()" href="Javascript:void(0);" class="a-l2-link
img-space" icon="fa-angle-right" [ngStyle]="{ 'disabled ': isHold }">Hold</a>