javascript ng-disabled 不适用于 span 标签
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33751611/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ng-disabled is not working on span tag
提问by Sunil Garg
There is a span tag with glyphicon icon that I want to disable.But ng-disabled is not working, that is the icon is still clickable.
有一个带有 glyphicon 图标的 span 标记,我想禁用它。但是 ng-disabled 不起作用,即该图标仍然可以点击。
<span ng-disabled="true" class="glyphicon glyphicon-trash" style="font-size:13px;" aria-hidden="true" ng-click="DeleteIpAdress(objIpAdress)" ng-show="objIpAdress.ShowRemoveButton" ng-model="objIpAdress.ShowRemoveButton" title="Delete IP address"></span>
Is anything wrong in the tag?
标签有什么问题吗?
采纳答案by Sunil Garg
ng-disabled doesn't work on span.So I disabled the click
ng-disabled 在 span 上不起作用。所以我禁用了点击
ng-click="disabledConditionHere || DeleteIpAdress(objIpAdress)"
and then changed the style of span by using class
然后使用 class 更改 span 的样式
.disable-span{
color: #E6E6E6;
cursor: not-allowed;
}
and used class in span tag
并在 span 标签中使用类
class="disable-span"
回答by Vivek
ng-disabled
directive works only with input fields and buttons. It does not work with span. Ref: ngDisabled Documentation
ng-disabled
指令仅适用于输入字段和按钮。它不适用于跨度。参考:ngDisabled 文档
You can prevent click action using following code
您可以使用以下代码阻止点击操作
ng-click="isClickAllowed && DeleteIpAdress(objIpAdress)"
回答by b85411
I had this same problem once, from memory the solution is to put the disabled condition in the ng-click.
我曾经遇到过同样的问题,根据记忆,解决方案是将禁用条件放在 ng-click 中。
ng-click="disabledConditionHere || DeleteIpAdress(objIpAdress)"
ng-click="disabledConditionHere || DeleteIpAdress(objIpAdress)"
回答by Satish Kotian
if you are using bootstrap add bootstrap class btn btn-xs
to the span
tag. This will fix ng-disabled
for span tag. Works in firefox.
如果您正在使用引导程序,请将引导程序类添加btn btn-xs
到span
标签中。这将修复ng-disabled
跨度标签。在火狐中工作。