MvcCaptcha 源代码 — mvccaptcha.js


 var _mvcCaptchaPrevGuid = null, _mvcCaptchaImgLoaded = false;

function _loadMvcCaptchaImage() {
    if (!_mvcCaptchaImgLoaded) {
        $.ajax({
            type: 'GET', url: '/_mvccaptcha/mvccaptchaloader/?' + _mvcCaptchaPrevGuid, global: false,
            success: function (data) {
                _mvcCaptchaImgLoaded = true;
                $("#_mvcCaptchaGuid").val(data);
                _mvcCaptchaPrevGuid = data;
                $("#captchaImage").html('<a href="javascript:_reloadMvcCaptchaImage()"><img src="/_mvccaptcha/mvccaptchaimage/?' + data + '" alt="MvcCaptcha" title="刷新图片" width="160" height="40" border="0"/></a><a href="javascript:_reloadMvcCaptchaImage()">换一张</a>');
            }
        });
    }
};

function _reloadMvcCaptchaImage() {
    _mvcCaptchaImgLoaded = false;
    _loadMvcCaptchaImage();
};

$(function () {
    if ($("#_mvcCaptchaText").length == 0) {
        alert("未能找到验证码输入文本框,请检查ValidationInputBoxId属性是否设置正确!");
    }
    if ($("#captchaImage").length == 0) { alert("未能找到验证码图片父容器,请检查CaptchaImageContainerId属性是否设置正确!"); }
    $("#_mvcCaptchaText").bind("focus", _loadMvcCaptchaImage)
});