Tecent Iphone Qzone Clint Login.js(相当规范)
2012-03-13 11:08
246 查看
$(function() { var qqInput=$("#qq"); var qqPholder=qqInput.attr("placeholder"); var pwdInput=$("#pwd"); var pwdPholder=pwdInput.attr("placeholder"); var setPlaceHolderAction= function(ele,def){ ele.focus(function(){ ele.attr("placeholder",""); if(ele.val().length<=0||ele.val()==def){ ele.val(""); } }); ele.blur(function(){ if(ele.val().length<=0){ ele.attr("placeholder",def); } }); }; setPlaceHolderAction(qqInput,qqPholder); setPlaceHolderAction(pwdInput,pwdPholder); var info = {}; var msgBox = $("#msg_box"), verifyBox = $("#verify_box"), lockMash = $("#bg_shadow"), loadingBox = $("#loading_box"); var curBox = msgBox; var w = $("body>div"); lockMash.width($(window).width()); lockMash.height($(document).height()); var timer; var orientationChange = function() { clearTimeout(timer); timer = setTimeout(function () { if(curBox.is(':visible')){ setCenter(curBox); lockMash.width($(window).width()); lockMash.height($(document).height()); } }, 500); } window.addEventListener("onorientationchange" in window ? "orientationchange" : "resize", orientationChange, false); var setCenter = function(box){ box.css({ top : (w.height() - box.height()) / 2 + "px", left : (w.position().left + (w.width() - box.width()) / 2) + "px" }); } var showLoading = function() { setCenter(loadingBox); curBox.hide(); loadingBox.show(); curBox = loadingBox; } var showPrompt = function(str) { $("#qq").attr("disabled",true); $("#pwd").attr("disabled",true); $("#mbox_txt").html(str); setCenter(msgBox); curBox.hide(); msgBox.show(); curBox = msgBox; } $("#mbox_cz_btn").click(function() { $("#qq").attr("disabled",false); $("#pwd").attr("disabled",false); msgBox.hide(); lockMash.hide(); }); var checkUinPwd = function() { var qq = $("#qq").val(); if (qq.length == 0 || qq < 10000) { showPrompt("请输入正确的帐号!"); return false; } var pwd = $("#pwd").val(); if (pwd.length == 0) { showPrompt("你还没有输入密码!"); return false; } var pmd5 = $.md5(pwd.substr(0, 16)); $("#pmd5").val(pmd5); return true; } var dealSubmitResult = function(str) { info = jQuery.parseJSON(str); if (info.code == 0) { if(info.goUrl){ curBox.hide(); lockMash.hide(); window.location.href = info.goUrl; }else showPrompt("参数错误!"); } else if (info.code == 40001) { showVerify(info); } else { showPrompt(info.msg); } } var doSubmit = function(verify) { lockMash.show(); var veriParam = ""; if (verify) { var code = $("#verify_code").val(); if (code.length == 0) { $("#vbox_txt").html("验证码不能为空"); return; } var u_token = $("#u_token").val(); veriParam += "&r_sid=" + info.rsid + "&verify=" + code + "&u_token=" + u_token; } else { if (!checkUinPwd()) return; } showLoading(); $.ajax({ type : "POST", url : "/login?act=json", data : $("#log_from :input[name!='pwd']").serialize() + veriParam, success : function(ret) { dealSubmitResult(ret); } }); } var showVerify = function() { $("#qq").attr("disabled",true); $("#pwd").attr("disabled",true); $("#vbox_txt").html(info.msg?info.msg:"输入图中的字符,不区分大小写"); $("#verify_code").val(""); $("#verify_img").attr( "src", info.vurl + ".gif?" + Math.floor(Math.random() * 10000) + new Date().getTime()); $("#u_token").val(info.u_token?info.u_token:"-1010"); verifyBox.css("top", $("#title").height + "px"); setCenter(verifyBox); curBox.hide(); verifyBox.show(); curBox = verifyBox; } $("#verify_img").click( function() { $("#verify_img").attr( "src", info.vurl + ".gif?" + Math.floor(Math.random() * 10000) + new Date().getTime()); }); $(".vbox_lg_btn").click(function() { $("#qq").attr("disabled",false); $("#pwd").attr("disabled",false); doSubmit(true); }); $('#pwd').keypress(function(e){ if(e.which == 13){ doSubmit(false); } }); $('#verify_code').keypress(function(e){ if(e.which == 13){ $("#qq").attr("disabled",false); $("#pwd").attr("disabled",false); doSubmit(true); } }); $(".vbox_cz_btn").click(function() { $("#qq").attr("disabled",false); $("#pwd").attr("disabled",false); verifyBox.hide(); $("#verify_code").val(""); lockMash.hide(); }); $(".lb_lg_btn").click(function() { doSubmit(false); }); });
相关文章推荐
- js获取iPhone 微信, qq ,uc, 的页面屏幕的高度
- IOS JSBox 安装 VSCode 通过插件JSBox 同步编辑代码到iPhone
- JS加载文件规范,AMD,commonJS,requireJs
- Batsing的网页编程规范(HTML/CSS/JS/PHP)
- js判断手机端(Android手机还是iPhone手机)
- js变量的命名规范
- js数据类型和变量命名规范
- CommonJS Modules/1.0 规范
- [置顶] Objective-C ,ios,iphone开发基础:命名规范
- js基础:数据类型,变量命名规范、
- Echarts异步模块定义(AMD规范)——require.js
- iPhone X 穿越回 1957 年计算力相当的电脑,将会是什么样?
- 外部引入的js函数代码规范(以jquery基础)
- 判断客户端js脚本-含ios、Android、iPhone、iPad
- JS如何判断是不是iphoneX
- Javascript模块化编程系列三: CommonJS & AMD 模块化规范描述
- js 规范
- JS判断浏览器iOS(iPhone)、Android手机移动端
- JS模块化编程之AMD规范(一)
- 也谈谈规范JS代码的几个注意点