伙计们,我发现停止表单提交存在问题。我有两个用户名和密码字段,如果用户名和密码相同,我想显示提醒并停止提交表单。这是我的代码
<form name="myform"ng-submit="checked()" action="change_credintls" method="post" enctype="multipart/form-data">
<input type="text"ng-model="username"name="username"class="form-control"maxlength="20" placeholder="ENTER NEW USERNAME"Required >
<input type="text"name="password"ng-model="pass"class="form-control"maxlength="20" placeholder="ENTER NEW PASSWORD"Required >
<input style="border-radius:0px;"type="submit" CLASS="btn btn-primary btn-sm"value="CHANGE CREDIANTLS">
</form>
这是我的角度代码
<script>
var app= angular.module('myapp',[]);
app.controller('mycntrl',function ($scope){
$scope.checked= function(myform)
{
if($scope.username == $scope.pass)
{
alert("Your user name and password can not be same");
return false;
}
}
});
</script>
警报正在运行,但我无法停止表单提交
答案 0 :(得分:1)
试试这个。
<强> HTML 强>
<form name="myform"ng-submit="checked($event)" action="change_credintls" method="post" enctype="multipart/form-data">
<input type="text"ng-model="username"name="username"class="form-control"maxlength="20" placeholder="ENTER NEW USERNAME"Required >
<input type="text"name="password"ng-model="pass"class="form-control"maxlength="20" placeholder="ENTER NEW PASSWORD"Required >
<input style="border-radius:0px;"type="submit" CLASS="btn btn-primary btn-sm"value="CHANGE CREDIANTLS">
<强> Anguler 强>
<script>
var app= angular.module('myapp',[]);
app.controller('mycntrl',function ($scope){
$scope.checked= function($event,myform)
{
if($scope.username == $scope.pass)
{
//alert("Your user name and password can not be same");
$event.preventDefault()
}
}
});
它应该适合你。