+function($) { "use strict"; $.fn.scrollheight = function(){ return this[0].scrollheight }; var getoffset = function(container) { var tagname = container[0].tagname.touppercase(); var scrolltop; if (tagname === 'body' || tagname === 'html') { scrolltop = container.scrolltop() || $(window).scrolltop() } else { scrolltop = container.scrolltop() }; var offset = container.scrollheight() - ($(window).height() + scrolltop); return offset }; var infinite = function(el, distance) { this.container = $(el); this.container.data("infinite", this); this.distance = distance || 50; this.attachevents() }; infinite.prototype.scroll = function() { var container = this.container; this._check() }; infinite.prototype.attachevents = function(off) { var el = this.container; var scrollcontainer = (el[0].tagname.touppercase() === "body" ? $(document) : el); scrollcontainer[off ? "off" : "on"]("scroll", $.proxy(this.scroll, this)) }; infinite.prototype.detachevents = function(off) { this.attachevents(true) }; infinite.prototype._check = function() { if($(".loadmore").hasclass("end"))return false; var offset = getoffset(this.container); if (offset < 0 && math.abs(offset) >= this.distance) { //往下拉 $(".loadmore").removeclass("end").addclass("show"); this.container.trigger("infinite"); return false; } }; var infinite = function(el) { if($(".loadmore").hasclass("end"))return false; attachevents(el) }; $.fn.infinite = function(distance) { return this.each(function() { new infinite(this, distance) }) }; $.fn.destroyinfinite = function() { return this.each(function() { var infinite = $(this).data("infinite"); if (infinite && infinite.detachevents) infinite.detachevents() }) } }($); jquery.extend({ left:function(mainstr,lnglen) { if (mainstr&&lnglen>0)return mainstr.substring(0,lnglen); return ''; }, right:function(mainstr,lnglen) { if (mainstr.length-lnglen>=0 && mainstr.length>=0 && mainstr.length-lnglen<=mainstr.length)return mainstr.substring(mainstr.length-lnglen,mainstr.length); return ''; }, mid:function(mainstr,starnum,endnum){ if (mainstr.length>=0)return mainstr.substr(starnum,endnum); return ''; }, cookie:function(a, b, c) { //example $.cookie('name','value',{expires:7,path:'/',domain:'jquery.com',secure:true}); if (typeof b != 'undefined') { c = c || {}; if (b === null) { b = ''; c = $.extend({}, c); c.expires = -1 } var d = ''; if (c.expires && (typeof c.expires == 'number' || c.expires.toutcstring)) { var e; if (typeof c.expires == 'number') { e = new date(); e.settime(e.gettime() + (c.expires * 24 * 60 * 60 * 1000)) } else { e = c.expires } d = '; expires=' + e.toutcstring() } var f = c.path ? ';path=' + (c.path) : ';path=/'; var g = c.domain ? '; domain=' + (c.domain) : ''; var h = c.secure ? '; secure' : ''; document.cookie = [a, '=', encodeuricomponent(escape(b)), d, f, g, h].join('') } else { var j = null; if (document.cookie && document.cookie != '') { var k = document.cookie.split(';'); for (var i = 0; i < k.length; i++) { var l = jquery.trim(k[i]); if (l.substring(0, a.length + 1) == (a + '=')) { j = unescape(decodeuricomponent(l.substring(a.length + 1))); break } } } return j } }, getnum:function(s,len){ // 字符串强制转换为数字,len=小数点后面长度 s=$.trim(s); if(!s)return 0; if(!number(s))return 0; if(len)s=s.tofixed(len); return parsefloat(s); }, get_value:function(dom){ if(!dom)return;dom='[name="'+dom+'"]:not(:disabled)'; if($(dom).length==0)return ""; var str="",type=$(dom).get(0).type,inputname=$(dom).get(0).tagname,sclass=$(dom+':first').attr("class"); type=type?type.tolowercase():""; inputname=inputname?inputname.tolowercase():""; if(type=="checkbox"){ dom=dom.replace(/\#/gi,"").replace(/\./,""); $('input'+dom+':checked').each(function(x){ str+=$(this).val()+','; }); str=jquery.trim(str); if (str.length-1>=0 && str.length>=0 && str.length-1<=str.length&&str.substring(str.length-1,str.length)==',')str=str.substring(0,str.length-1); }else if(type=="radio"){ str=$(dom+":checked").val(); str=jquery.trim(str); }else{ dom=dom.replace(/\#/gi,"").replace(/\./,""); $(inputname+dom).each(function(x){ if($(this).val())str+=$(this).val()+','; }); str=jquery.trim(str); if (str.length-1>=0 && str.length>=0 && str.length-1<=str.length&&str.substring(str.length-1,str.length)==',')str=str.substring(0,str.length-1); }; return $.trim(str); }, querystring:function(name) { var reg = new regexp("(^|&)" + name + "=([^&]*)(&|$)", "i"); var r = window.location.search.substr(1).match(reg); if (r != null) return unescape(r[2]); return null; }, clearhtml:function(str){ return str.replace(/<(?:.|\s)*?>/g,""); }, fornumber:function(num) {//格式化数字成两位小数 num = num.tostring().replace(/\$|\,/g,''); if(isnan(num)) num = "0"; sign = (num == (num = math.abs(num))); num = math.floor(num*100+0.50000000001); cents = num%100; num = math.floor(num/100).tostring(); if(cents<10) cents = "0" + cents; for (var i = 0; i < math.floor((num.length-(1+i))/3); i++) num = num.substring(0,num.length-(4*i+3))+','+ num.substring(num.length-(4*i+3)); return (((sign)?'':'-') + num + '.' + cents); } }); var han={}, // 通用 prvstudy=0, // 上次学习的进度 page=1, // 起始页码 allpage=0, // 所有页数 index=1, // 当前位置 load_close=function(){// 关闭load $(".load").removeclass("show"); }, load=function(str){ load_close(); str=str?str:""; $(".load").addclass("show").find("p").html(str); }, alert_close=function(){ $("#alert").removeclass("show"); }, get=function(data,callback){ $.ajax({ type:"get", beforesend:function(){$(".loadmore").addclass("show");}, url:"/ajax/ajax_get.html", datatype:"json", data:data, success:function(result){ if(callback){ callback(result) }else{ load_close(); }; $(".loadmore").removeclass("show"); } }); }; han.alert=function(info,title,callback){ alert_close(); if(typeof title=="function"){ callback=title; title=""; }; title=title?title:"提示"; $("#alert .alert_title").html(title); $("#alert .alert_content").html(info); $("#alert a").removeclass("hide"); $("#alert .cancle").addclass("hide"); $("#alert").addclass("show").find("a.sure").unbind().bind("click",function(){ if(callback){ callback(true); alert_close(); }else{ alert_close(); }; }); }; han.confirm=function(info,title,sure,cancle){ alert_close(); if(typeof title=="function"){ if(sure){ cancle=sure; sure=title; title=""; }else{ sure=title; title=""; }; }; title=title?title:"提示"; $("#alert .alert_title").html(title); $("#alert .alert_content").html(info); $("#alert a").removeclass("hide"); $("#alert").addclass("show").find("a.sure").unbind().bind("click",function(){ if(sure){ sure(true); alert_close(); }else{ alert_close(); }; }); $("#alert").find("a.cancle").unbind().bind("click",function(){ if(cancle){ cancle(false); alert_close(); }else{ alert_close(); }; }); };