我想仅在输入字段中输入文本时启用按钮。到目前为止,我的 app.js 上有这段代码
.controller("EnableDisable", function(){
$scope.editableInput = false;
})
.directive("inputDisabled", function(){
return function(scope, element, attrs){
scope.$watch(attrs.inputDisabled, function(val){
if(val)
element.removeAttr("disabled");
else
element.attr("disabled", "disabled");
});
}
});
这是视图实现:
<div ng-controller="EnableDisable">
<input type="text" input-disabled="editableInput" />
<button ng-click="editableInput = !editableInput">enable/disable</button>
</div>
这是 plunk 网址:https://plnkr.co/edit/bHtZJ1H5JvM2XTuhft6J?p=preview目前,当我启动应用程序时,默认情况下该按钮未禁用。
请面对上述挑战,当在输入字段中输入文本时,如何使按钮可单击(接收事件)。
请帮忙!
你可以用 Angular 来做到这一点。
<input type="text" ng-model="textEntered" />
<button ng-disabled="!textEntered">Continue</button>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)