Array.prototype.indexOf = function (searchElement, fromIndex) { if ( this === undefined || this === null ) { throw new TypeError( '"this" is null or not defined' ); } var length = this.length >>> 0; // Hack to convert object.length to a UInt32 fromIndex = +fromIndex || 0; if (Math.abs(fromIndex) === Infinity) { fromIndex = 0; } if (fromIndex < 0) { fromIndex += length; if (fromIndex < 0) { fromIndex = 0; } } for (;fromIndex < length; fromIndex++) { if (this[fromIndex] === searchElement) { return fromIndex; } } return -1; }; var NextDate=[]; var globalDates=[]; function GetAllDate(syear,smonth) {//获取当月的全部日期 var result=[]; jQuery.ajax({ url:"../../../period/"+syear+smonth+"/period.js?_t="+Math.random(), type:"GET", async:false, cache:false, dataType:"script", success:function(data) { eval(data); result=datelist; }, error:function(err){ result=[];} }); return (result); } function hasData(syear,smonth,sday,ppname) { var result=""; if(globalDates.length>0) { result=globalDates.indexOf(syear+smonth+sday); return (result!=-1); } if(ppname&&""!=ppname) { resURL="../"+ppname+"/period/"+syear+smonth+"/period.js?_t="+Math.random(); //weixin } else { resURL="../../../period/"+syear+smonth+"/period.js?_t="+Math.random(); //PC,Mobile } // alert(window.location); jQuery.ajax({ url:resURL, type:"GET", async:false, cache:false, dataType:"script", success:function(data) { eval(data); result=datelist.indexOf(syear+smonth+sday); globalDates=datelist; }, error:function(err){ result=-1; } }); return (result!=-1); } function getFirstPage(syear,smonth,sday,ppname) { var result="",resURL=""; if(ppname&&""!=ppname) { resURL="../"+ppname+"/period/firstpage.js?_t="+Math.random(); } else { resURL="../../../period/firstpage.js"; } jQuery.ajax({ url:resURL, type:"GET", async:false, cache:false, dataType:"script", success:function(data) { eval(data); result= pagelist[syear+smonth+sday][0]; }, error:function(err){ result=-1; } }); return result; } function getFirstPage2(sRiqi) { var result=""; jQuery.ajax({ url:"../../../period/firstpage.js?_t="+Math.random(), type:"GET", async:false, cache:false, dataType:"script", success:function(data) { eval(data); result= pagelist[sRiqi][0]; }, error:function(err){ result=-1; } }); return result; } //获得当前月最大天数 function maxDay(year,month){ return new Date(year, month,0).getDate(); } function goNextPeriod(curYMD){ //下一期 //curYMD=20161231 // alert("curYMD="+curYMD); if ( datelist.indexOf(curYMD)===datelist.length-1) { if("12"==curYMD.substr(4,2)) { var oldYear=curYMD.substr(0,4)*1;//年 var newYear=oldYear+1; //年+1 curYMD=(""+newYear)+"0133"; //开始新的一年 } } var nextDate=GetAllDate(curYMD.substr(0,4),curYMD.substr(4,2)); //alert("nextDate="+nextDate); var curindx=-1; var firstpage=getFirstPage2(curYMD); if('0133'==curYMD.substr(4,4)) { nextdate=nextDate[0]; window.location.href="../../../"+nextdate.substr(0,4)+"/"+nextdate+"/"+nextdate+"_"+firstpage+"/"+nextdate+"_"+firstpage+".html"; } curindx=nextDate.indexOf(curYMD); var nextdate=""; ++curindx; if(curindx<=nextDate.length-1) { nextdate=nextDate[curindx]; window.location.href="../../../"+nextdate.substr(0,4)+"/"+nextdate+"/"+nextdate+"_"+firstpage+"/"+nextdate+"_"+firstpage+".html"; } else { var currentURL=window.location.href; // alert(currentURL);//http://localhost:916/web/zgjcb/DATA/2016/20160301/20160301_001/20160301_001.html# var lpos=currentURL.lastIndexOf("/")+1; var dotpos=currentURL.lastIndexOf("_"); var _YMD=currentURL.substr(lpos,dotpos-lpos); var _Y=_YMD.substr(0,4); var _M=_YMD.substr(4,2); var _D=_YMD.substr(6,2); var curDate=new Date(_Y,(_M*1)-1,_D*1+1); //modified by yang at 2016.5.27 if(_D*1==maxDay(_Y,_M)) { //得到后一个日期 var sm=curDate.getMonth()+1; if(sm.toString().length==1) sm="0"+sm; goPrevPeriod(_Y+sm+"01",true); return ; } else { //当从4月29,到 5月 3日,这个跳跃间距太大 var sm=(curDate.getMonth()+1)+1; if(sm.toString().length==1) sm="0"+sm; var nextDate=GetAllDate(_Y,sm); if(nextDate.length>0) { goPrevPeriod(nextDate[0],true); } else alert('没有下一期了!'); return ; } alert('没有下一期了!'); } } function goPrevPeriod(curYMD,bz){ //上一期 if ( datelist.indexOf(curYMD)===0) { if("01"==curYMD.substr(4,2)) { var curYear=curYMD.substr(0,4)*1;//年 var prevYear=curYear-1; //年-1 curYMD=(""+prevYear)+"1232"; //前一年 } } var firstpage=getFirstPage2(curYMD); var nextDate=GetAllDate(curYMD.substr(0,4),curYMD.substr(4,2)); var curindx=-1; if("1232"==curYMD.substr(4,4)) { nextdate=nextDate[nextDate.length-1]; window.location.href="../../../"+nextdate.substr(0,4)+"/"+nextdate+"/"+nextdate+"_"+firstpage+"/"+nextdate+"_"+firstpage+".html"; } curindx=nextDate.indexOf(curYMD); var nextdate=""; if(!bz) --curindx; if(curindx>=0) { nextdate=nextDate[curindx]; window.location.href="../../../"+nextdate.substr(0,4)+"/"+nextdate+"/"+nextdate+"_"+firstpage+"/"+nextdate+"_"+firstpage+".html"; } else { var currentURL=window.location.href; // alert(currentURL);//http://localhost:916/web/zgjcb/DATA/2016/20160301/20160301_001/20160301_001.html# var lpos=currentURL.lastIndexOf("/")+1; var dotpos=currentURL.lastIndexOf("_"); var _YMD=currentURL.substr(lpos,dotpos-lpos); var _Y=_YMD.substr(0,4); var _M=_YMD.substr(4,2); var _D=_YMD.substr(6,2); var curDate=new Date(_Y,_M-1,_D-1); var curPubDate=new Date(_Y,Math.floor(_M)-1,_D-1); var oldPubDate=new Date("2016","0","31");//2016.2.1 之前的数据为旧版电子数据 if(curPubDate<=oldPubDate) { //alert('为旧版数据'); var oldYear=curPubDate.getFullYear(); var oldMonth=curPubDate.getMonth()+1; if(oldMonth.toString().length==1) oldMonth="0"+oldMonth; var oldDay=curPubDate.getDate(); var url="http://newspaper.jcrb.com/html/"+oldYear+"-"+oldMonth+"/"+oldDay+"/node_2.htm"; window.open(url,"_blank"); return ; } var nextCurDate=GetAllDate(_Y,_M); if(nextCurDate.length>0 && nextCurDate[0]==_YMD) { var sm=curDate.getMonth()+1; var sd=curDate.getDate(); if(sm==_M) sm=sm*1-1; if(sm.toString().length==1) sm="0"+sm; if(sd.toString().length==1) sd="0"+sd; //alert(_Y+sm+sd+' '+_YMD); var nextDate=GetAllDate(_Y,sm); if(nextDate.length>0) { goPrevPeriod(nextDate[nextDate.length-1],true); } return ; } else alert('没有上一期了!'); // alert('没有上一期了!'); } } $(function () { var yearContent = ''; var yearData = new Date().getFullYear(); var selectVal = $('#mYear').val() for (var i=2016; i<=yearData; i++) { yearContent += '' } $('#mYear').html(yearContent) $('#mYear').val(selectVal) $('.jumpmenu').css({ 'padding': '0 10px' }) })