1 /** 2 * 3 * 验证码 4 * 5 * @fileOverView 6 * @author <a href="mailto:zhang.gd@foxmail.com">zhangguangda</a> 7 * @date 2012-12-4 8 */ 9 ; 10 define( 11 function() { 12 /** 13 * 验证码 14 * @lends $we.widget.captcha 15 */ 16 var _html = [ 17 '<div attr="root">', 18 '<img attr="img" style="margin-left:130px" />', 19 '<a attr="click:changeCaptcha" style="margin-left:10px;" href="javascript:void(0);">看不清,换一张</a>', 20 '</div>' 21 ].join(""), 22 _captchaUrl = 'http://captcha.sdo.com/fcgi-bin/show_img.fcgi?appid=470&gameid=0&areaid=-1&user=&image_type=0&session_key='; 23 24 $we.widget.reg("captcha", { 25 /** 26 * @constructs 27 * @param {Element} el 节点 28 * @param {String} key Captcha Key 29 */ 30 init: function(el, key) { 31 this.key = key; 32 this.append(el, _html); 33 this.node.img.src = _captchaUrl + this.key + "&" + (+new Date); 34 }, 35 /** 36 * interfaces 37 * @memberOf $we.widget.captcha# 38 */ 39 interfaces: { 40 /** 41 * 换一个验证码 42 * @memberOf $we.widget.captcha# 43 */ 44 change: function() { 45 this.node.img.src = _captchaUrl + this.key + "&" + (+new Date); 46 }, 47 /** 48 * 换验证码Key 49 * @memberOf $we.widget.captcha# 50 * @param {String} key Captcha Key 51 */ 52 changeKey: function(key) { 53 if (!key) return; 54 this.key = key; 55 this.change(); 56 } 57 }, 58 /** 59 * events 60 * @memberOf $we.widget.captcha- 61 */ 62 events: { 63 /** 64 * 更换验证码事件 65 * @memberOf $we.widget.captcha- 66 */ 67 changeCaptcha: function() { this.change(); } 68 } 69 }); 70 71 return $we.widget.amd("captcha"); 72 } 73 );