我在使用bPopup插件的弹出式对话框中使用了简单的验证码。如何在指令中重新加载简单的验证码?
您可以参考图形验证码本的jsfiddle:https://jsfiddle.net/Mazzu/hspxaeqa/
HTML:
<span id="popup-button-email">Click Here!</span>
<div id="popup-second"> <a class="b-close">x<a/>
<simple-captcha valid="captchaValid"></simple-captcha>
</div>
JS:
app.directive('simpleCaptcha', function() {
return {
restrict: 'E',
scope: { valid: '=' },
template: '<input ng-model="a.value" ng-show="a.input" style="width:2em; text-align: center;"><span ng-hide="a.input">{{a.value}}</span> {{operation}} <input ng-model="b.value" ng-show="b.input" style="width:2em; text-align: center;"><span ng-hide="b.input">{{b.value}}</span> = {{result}}',
controller: function($scope) {
var show = Math.random() > 0.5;
var value = function(max){
return Math.floor(max * Math.random());
};
var int = function(str){
return parseInt(str, 10);
};
$scope.a = {
value: show? undefined : 1 + value(4),
input: show
};
$scope.b = {
value: !show? undefined : 1 + value(4),
input: !show
};
$scope.operation = '+';
$scope.result = 5 + value(5);
var a = $scope.a;
var b = $scope.b;
var result = $scope.result;
var checkValidity = function(){
if (a.value && b.value) {
var calc = int(a.value) + int(b.value);
$scope.valid = calc == result;
} else {
$scope.valid = false;
}
$scope.$apply(); // needed to solve 2 cycle delay problem;
};
$scope.$watch('a.value', function(){
checkValidity();
});
$scope.$watch('b.value', function(){
checkValidity();
});
}
};
});
跳出:
$('#popup-button-email').bind('click', function(e) {
// Prevents the default action to be triggered.
e.preventDefault();
// Triggering bPopup when click event is fired
$('#popup-second').bPopup();
});
所有看起来不错,除了o ne的东西。
关闭弹出窗口后,我打开另一个弹出窗口,但没有重新载入验证码,这很奇怪。
任何想法如何在关闭弹出窗口后重新载入验证码?
谢谢
我所看到的只是样本中的一项工作评估。你为什么混合jquery和angular?这可能是原因的一部分。不知道你的意思是重新加载。控制器不会再运行。您可能应该有一个函数'loadCaptcha()',并在控制器加载时调用一次,并在弹出窗口关闭时再次调用该函数。 – Brian