为什么我的按钮无法启用和禁用此代码:
<form name="formSendEmail" ng-submit="sendEmailAction();">
<div class="form-group">
<label class="label label-muted" for="visitorEmailForSendEmail">Visitor E-mail</label>
<input type="email" value="{{visitorDetail2.EmailAddress}}" id="visitorEmailForSendEmail" name="visitorEmailForSendEmail" class="form-control" ng-required="true" />
</div>
<input type="submit" class="btn btn-primary" value="Send E-mail" ng-disabled="formSendEmail.$invalid" />
</form>
在该代码之上,我有另一个名称为formCreateItinerary
的表单,我将ng-disabled
更改为指向该表单;启用和禁用按钮的工作原理。
我也使用过这段代码:
<input type="submit" class="btn btn-primary" value="Send E-mail" ng-disabled="visitorEmailForSendEmail == undefined || visitorEmailForSendEmail == ''" />
使用此代码,该按钮被禁用且无法启用。你能帮忙吗?
答案 0 :(得分:0)
尝试将value="{{visitorDetail2.EmailAddress}}"
更改为ng-model="visitorDetail2.EmailAddress"
<input type="email" ng-model="emailAddress" ng-change="validateEmail(emailAddress)" id="visitorEmailForSendEmail" name="visitorEmailForSendEmail" class="form-control" ng-required="true" />
<button ng-disabled="disableButton">button</button>
$scope.validateEmail=function(email) {
if(!validateEmail(email)){
$scope.disableButton=true;
}else{
$scope.disableButton=false;
}
}
function validateEmail(email) {
var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email);
}