javascript Angularjs - 复选框禁用和启用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19963549/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 17:22:39  来源:igfitidea点击:

Angularjs - Checkbox disabling and enabling

javascriptangularjs

提问by GRowing

I am looking for a way to do exactly opposite from this example that was taken from angularjs ng-disabled documentation ... http://docs.angularjs.org/api/ng.directive:ngDisabled

我正在寻找一种与这个例子完全相反的方法,这个例子取自 angularjs ng-disabled 文档...... http://docs.angularjs.org/api/ng.directive:ngDisabled

In this example checking the box disables the button. I need exactly the opposite,,, I need the checked box to enable a disabled button. Can someone shed some light on this for me please.

在此示例中,选中该框将禁用该按钮。我需要完全相反的,我需要复选框来启用禁用的按钮。有人可以为我解释一下吗?

<!doctype html>
<html ng-app>
<head>
<script src="http://code.angularjs.org/1.2.0/angular.min.js"></script>
</head>
<body>
Click me to toggle: <input type="checkbox" ng-model="checked"><br/>
<button ng-model="button" ng-disabled="checked">Button</button>
</body>
</html>

Thanks!

谢谢!

回答by tymeJV

You can do:

你可以做:

ng-disabled="!checked"

The !means to do the opposite, so !true == false = true

!做相反的手段,所以!true == false = true

Plunkr: http://plnkr.co/edit/ht0z3lTJi8EfPJEKWcWl?p=preview

Plunkr:http://plnkr.co/edit/ht0z3lTJi8EfPJEKWcWl?p=preview