使用angularjs按钮的验证码示例单击验证

时间:2016-04-13 13:44:30

标签: jquery angularjs

我尝试了这个要求我在j查询中获得了验证码验证,但我想验证角度点击按钮。请看我的小提琴一旦尝试解决请帮助我。提前谢谢。请在我的小提琴中按下刷新按钮然后只生成验证码。请解决那个负载也

我想使用angular执行相同的代码。如何将jquery更改为angular请任何人将其更改为角度代码或我想使用ng-click验证

var app = angular.module('app', []);

app.controller('Ctrl', function($scope){
    $scope.submit=function(){
    alert("hi");
    }
});

function Captcha() {
    var alpha = new Array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');
    var i;
    for (i = 0; i < 6; i++) {
        var a = alpha[Math.floor(Math.random() * alpha.length)];
        var b = alpha[Math.floor(Math.random() * alpha.length)];
        var c = alpha[Math.floor(Math.random() * alpha.length)];
        var d = alpha[Math.floor(Math.random() * alpha.length)];
        var e = alpha[Math.floor(Math.random() * alpha.length)];
        var f = alpha[Math.floor(Math.random() * alpha.length)];
        var g = alpha[Math.floor(Math.random() * alpha.length)];
    }
    var code = a + ' ' + b + ' ' + ' ' + c + ' ' + d + ' ' + e + ' ' + f + ' ' + g;
    document.getElementById("mainCaptcha").value = code
}
function ValidCaptcha() {
    var string1 = removeSpaces(document.getElementById('mainCaptcha').value);
    var string2 = removeSpaces(document.getElementById('txtInput').value);
    if (string1 == string2) {
        return true;
    }
    else {
        return false;
    }
}
function removeSpaces(string) {
    return string.split(' ').join('');
}

http://jsfiddle.net/hspxaeqa/10/

1 个答案:

答案 0 :(得分:1)

请参阅下面的jsFiddle

captcha in Angularway

var app = angular.module('app', []);

app.controller('Ctrl', function($scope){
$scope.submit=function(){
alert("hi");
}

$scope.Captcha = function() {
var alpha = new Array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');
var i;
var code = "";
for (i = 0; i < 6; i++) {
    code = code + alpha[Math.floor(Math.random() * alpha.length)] + " ";
}
$scope.mainCaptcha = code;
}

$scope.ValidCaptcha = function () {
var string1 = removeSpaces($scope.mainCaptcha);
var string2 = removeSpaces($scope.c);
if (string1 == string2) {
    alert(true);
}
else {
    alert(false);
}
}

removeSpaces = function (string) {
return string.split(' ').join('');
}

});