我在使用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