javascript 如果复选框被选中,Angularjs 禁用按钮

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

Angularjs disable button if checkbox is checked

javascriptangularjscheckbox

提问by 1313

I have a button on a form that I'd like to disable until one or more checkboxes have been selected. This is probably fairly simple to solve, but the button is not disabled when I use !result.isSelected.

我在表单上有一个按钮,在选中一个或多个复选框之前,我想禁用该按钮。这可能很容易解决,但是当我使用 !result.isSelected 时,按钮并没有被禁用。

This is my button:

这是我的按钮:

<button class="btn btn-success" ng-click="send()"  ng-disabled="!result.isSelected" </button>

And the checkbox:

和复选框:

<input type="checkbox" class="checkbox-row" ng-model="result.isSelected" ng-click="selected()" />

Does anyone know of a better solution? Thanks for your help!

有谁知道更好的解决方案?谢谢你的帮助!

回答by Sajal

A better solution would be:

更好的解决方案是:

<input type="checkbox" class="checkbox-row" ng-model="checked" ng-click="selected()" />

<button class="btn btn-success" ng-click="send()"  ng-disabled="!checked"> </button>