var letan={}; //定义对象 letan.formdata=function(form){ //表单数据转换为js对象 var data = {}; var fields = $(form).serializearray(); $.each(fields, function() { if (data[this.name] !== undefined) { if (!data[this.name].push) { data[this.name] = [data[this.name]]; } data[this.name].push(this.value || ''); } else { data[this.name] = this.value || ''; } }); return data; } letan.numbertomoney=function(num){ //数字转换为两位小数 if(num!=null && !isnan(num)){ return parsefloat(num).tofixed(2); } return "0.00"; } letan.refresh=function(){ //刷新网页 location.reload(); } letan.redirect=function(url){ //网页重定向 location.href=url; } letan.iswechat=function(){ //判断是否为微信浏览器 var ua = window.navigator.useragent.tolowercase(); if(ua.match(/micromessenger/i) == 'micromessenger'){ return true; }else{ return false; } } letan.call=function(url, params,options){ //ajax处理 var option = {}; option.validate = function(){ return true; } option.beforesubmit = function(){ //console.log('beforesubmit >>>> do you need me show animation ?'); }; option.success = function(response){ // console.log('success >>>>'+response); }; option.error = function(response){ // console.log('error >>>>'+response); }; option.complete = function(){ // console.log('complete >>>> do you need me close animation ?'); }; $.extend(option,options); //do validation if(!option.validate()){ return false; } option.beforesubmit(); $.ajax(url, { 'datatype': 'json', // if you want to cross domain post jsonp 'type':"post",// if you want to cross domain post ,you should use get 'traditional': true, // server only supports traditional style params 'data': params, 'success': function(response, status, xhr){ // 跨域时,开启 option.success(response); }, 'error': function(xhr, status, error){ var response = {}; // parse json response try{ response = $.parsejson(xhr.responsetext); }catch(e){ error = 'parse_error'; response = 'parse json error!'; } option.error(response); }, 'complete':function(res){ option.complete(); }//end complete }); } letan.tip=function(txt){ //信息提示 times = 2500; if($(".letantips").length > 0){ return; } var tipsobj = $('

'+ txt + '

'); $("body").append(tipsobj); settimeout(function(){ $(".letantips").animate({opacity:0}, 500, function(){ $(".letantips").remove(); }); }, times); } letan.tipreload=function(txt){ //提示后刷新 times = 2500; if($(".letantips").length > 0){ return; } var tipsobj = $('

'+ txt + '

'); $("body").append(tipsobj); settimeout(function(){ $(".letantips").animate({opacity:0}, 500, function(){ $(".letantips").remove(); location.reload(); }); }, times); } letan.tipredirect=function(txt,url){ //提示后跳转 times = 2500; if($(".letantips").length > 0){ return; } var tipsobj = $('

'+ txt + '

'); $("body").append(tipsobj); settimeout(function(){ $(".letantips").animate({opacity:0}, 500, function(){ $(".letantips").remove(); location.href=url; }); }, times); } window.letan = letan;