摘自启点的main.js_Javascript教程-查字典教程网
摘自启点的main.js
摘自启点的main.js
发布时间:2016-12-30 来源:查字典编辑
摘要:String.prototype.trim=function(){returnthis.replace(/(^s*)|(s*$)/g,"")...

String.prototype.trim=function()

{

returnthis.replace(/(^s*)|(s*$)/g,"");

}

String.prototype.len=function()

{

returnthis.replace(/[^x00-xff]/g,'aa').length;

}

functionStringBuilder(value)

{

this.strings=newArray("");

this.append(value);

}

//Appendsthegivenvaluetotheendofthisinstance.

StringBuilder.prototype.append=function(value)

{

if(value)

{

this.strings.push(value);

}

}

//Clearsthestringbuffer

StringBuilder.prototype.clear=function()

{

this.strings.length=1;

}

//ConvertsthisinstancetoaString.

StringBuilder.prototype.toString=function()

{

returnthis.strings.join("");

}

//stringformatprototype

//sample:vartest="mynameis{0}{2}";

//alert(test.format('liang','zhonghua');

if(!String._FORMAT_SEPARATOR){

String._FORMAT_SEPARATOR=String.fromCharCode(0x1f);

String._FORMAT_ARGS_PATTERN=newRegExp('^[^'+String._FORMAT_SEPARATOR+']*'

+newArray(100).join('(?:.([^'+String._FORMAT_SEPARATOR+']*))?'));

}

if(!String.format)

{

String.format=function(s){

returnArray.prototype.join.call(arguments,String._FORMAT_SEPARATOR).

replace(String._FORMAT_ARGS_PATTERN,s);

}

}

if(!''.format)

{

String.prototype.format=function(){

return(String._FORMAT_SEPARATOR+

Array.prototype.join.call(arguments,String._FORMAT_SEPARATOR)).

replace(String._FORMAT_ARGS_PATTERN,this);

}

}

//endstringformat

functioncheckLoginByCookie()

{

varcookieId="AUTHTEST";

if(window.location.href.toLowerCase().indexOf("qidian.com")>-1)

{

cookieId="cmfuToken";

}

if((GetCookie(cookieId)!=null&&GetCookie(cookieId).length>0))

{

returntrue;

}

else

{

if(GetCookie('cmfu_al')!=null&&GetCookie('cmfu_al').length>0)

{

returntrue;

}

}

returnfalse;

}

functiongetUrlParam(name)

{

varreg=newRegExp("(^|&)"+name+"=([^&]*)(&|$)","i");

varr=window.location.search.substr(1).match(reg);

if(r!=null)

{

returnunescape(r[2]);

}

else

{

returnnull;

}

}

function$(objName)

{

if(document.getElementById)

{

returndocument.getElementById(objName);

}

elseif(document.layers)

{

returneval("document.layers['"+objName+"']");

}

else

{

returneval('document.all.'+objName);

}

}

functionDateAdd(BaseDate,interval,DatePart)

{

vardateObj=newDate(BaseDate.replace("-",","));

varmillisecond=1;

varsecond=millisecond*1000;

varminute=second*60;

varhour=minute*60;

varday=hour*24;

varyear=day*365;

varnewDate;

vardVal=newDate(dateObj)

vardVal=dVal.valueOf();

switch(DatePart)

{

case"ms":newDate=newDate(dVal+millisecond*interval);break;

case"s":newDate=newDate(dVal+second*interval);break;

case"mi":newDate=newDate(dVal+minute*interval);break;

case"h":newDate=newDate(dVal+hour*interval);break;

case"d":newDate=newDate(dVal+day*interval);break;

case"y":newDate=newDate(dVal+year*interval);break;

default:returnescape("日期格式不对");

}

newDate=newDate(newDate);

returnnewDate.getFullYear()+"-"+(newDate.getMonth()+1)+"-"+newDate.getDate();

}

//增加当前日期的天数

Date.prototype.AddDays=function(interval)

{

vardateObj=this;

varmillisecond=1;

varsecond=millisecond*1000;

varminute=second*60;

varhour=minute*60;

varday=hour*24;

varyear=day*365;

varnewDate;

vardVal=newDate(dateObj)

vardVal=dVal.valueOf();

newDate=newDate(dVal+day*interval);

newDate=newDate(newDate);

returnnewDate

}

functionSetCookie(name,value)

{

varargv=SetCookie.arguments;

varargc=SetCookie.arguments.length;

varexpires=(argc>2)?argv[2].toGMTString():(newDate()).AddDays(30).toGMTString();;

varpath=(argc>3)?argv[3]:"/";

vardomain=(argc>4)?argv[4]:null;

varsecure=(argc>5)?argv[5]:false;

varcontent=name+"="+escape(value)+";";

if(expires!=null)

{

content+="expires="+expires+";";

}

if(path!=null)

{

content+="path="+path+";";

}

if(domain!=null)

{

content+="domain="+domain+";";

}

document.cookie=content;

}

functionGetCookie(cookieName)

{

varcookieString=document.cookie;

varstart=cookieString.indexOf(cookieName+'=');

//加上等号的原因是避免在某些Cookie的值里有

//与cookieName一样的字符串。

if(start==-1)//找不到

returnnull;

start+=cookieName.length+1;

varend=cookieString.indexOf(';',start);

if(end==-1)returnunescape(cookieString.substring(start));

returnunescape(cookieString.substring(start,end));

}

/*文本框得到焦点*/

functionTextBoxOnFocus(txtControl,strDefaultText)

{

if(txtControl.value==strDefaultText)

txtControl.value="";

}

/*文本框失去焦点*/

functionTextBoxOnBlur(txtControl,strDefaultText)

{

if(txtControl.value.replace(/(^[s]*)|([s]*$)/g,"")=="")

txtControl.value=strDefaultText;

}

/*功能:弹出群发消息窗口*/

functionMultiSendWin(subject,content)

{

varwin=window.open(uploadURL+"?subject="+subject+"&content="+content,"","menubar=no,width=480,height=550,resizeable=no","");

returnfalse;

}

/*功能:弹出留言窗口

functionSpaceSendMsg(toUserId)

{

varwin=window.open(spaceSendMsgURL+"?toUserId="+toUserId,"","menubar=no,width=500,height=400,resizeable=no","");

returnfalse;

}

*/

functionShowServerMessage(result)

{

eval(result.value);

}

//回车提交表单

functionKeydownSubmitForm(btnId)

{

varbtn=document.getElementById(btnId);

if(btn!=null&&event.keyCode==13)

{

event.returnValue=false;

event.keyCode=9;

btn.click();

}

}

//ReadChapter-抵用券js

functionMDown(Object){

Obj=Object.id

document.all(Obj).setCapture()

pX=event.x-document.all(Obj).style.pixelLeft;

pY=event.y-document.all(Obj).style.pixelTop;

}

functionMMove(){

if(Obj!=''){

document.all(Obj).style.left=event.x-pX;

document.all(Obj).style.top=event.y-pY;

}

}

functionMUp(){

if(Obj!=''){

document.all(Obj).releaseCapture();

Obj='';

}

}

//关闭抵用券信息

functionLayerClose(divDiscount){

document.getElementById(divDiscount).style.visibility="hidden";

}

//显示抵用券信息

functionLayerShow(divDiscount,discountPrize){

varprizeUI=document.getElementById(divDiscount);

prizeUI.style.left=screen.width-530;

prizeUI.style.top=screen.Height-480;

prizeUI.style.visibility="visible";

document.getElementById("lblPrize1").innerHTML=discountPrize;

document.getElementById("lblPrize2").innerHTML=discountPrize;

window.setInterval("LayerClose('"+divDiscount+"')",15000);

}

//帮助masterpage用

functionHideMenu(menuid)

{

varobj=document.getElementById(menuid);

if(obj.style.display=="none")

{

obj.style.display="";

}

else

{

obj.style.display="none";

}

if(obj.style.display=="")

{

vartmpId="M0";

for(vari=1;i<=9;i++)

{

varmyid=tmpId+i;

if(myid!=menuid)

{

document.getElementById(myid).style.display="none";

}

}

}

}

/*divlogin*/

functionShowLoginDiv()

{

varbuilder=newStringBuilder();

builder.append("<tableborder='0'cellpadding='0'cellspacing='0'>");

builder.append("<trclass='TitleTR'>");

builder.append("<tdalign='left'>");

builder.append("登录");

builder.append("</td>");

builder.append("<tdalign='right'>");

builder.append("<spantitle='关闭'onclick='HideLoginMask();'>×</span>");

builder.append("</td>");

builder.append("</tr>");

builder.append("<tr>");

builder.append("<tdcolspan='2'>");

builder.append("<iframesrc='/DivUserLogin.aspx'width='225px'height='125px'name='loginFrame'");//src=''

builder.append("id='loginFrame'frameborder='0'scrolling='no'></iframe>");

builder.append("</td>");

builder.append("</tr>");

builder.append("</table>");

//window.top.scrollTo(0,0);

document.getElementById("DivMask").style.height=document.body.scrollHeight;

document.getElementById("DivMask").style.width=document.body.scrollWidth;

document.getElementById("DivMask").style.display='block';

document.getElementById("DivLogin").style.display="block";

document.getElementById("DivLogin").innerHTML=builder.toString();

ScrollDiv();

window.onscroll=ScrollDiv;

window.onresize=ScrollDiv;

window.onload=ScrollDiv;

}

functionHideLoginMask()

{

document.getElementById("DivMask").style.display="none";

document.getElementById("DivLogin").style.display="none";

}

/*随屏幕滚动*/

functionScrollDiv()

{

if($("DivLogin"))

{

document.getElementById("DivLogin").style.top=(document.body.scrollTop+

(document.body.clientHeight-document.getElementById("DivLogin").offsetHeight)/2)+"px";

document.getElementById("DivLogin").style.left=(document.documentElement.scrollLeft+

(document.body.clientWidth-document.getElementById("DivLogin").offsetWidth)/2)+"px";

}

if($("AddMark"))

{

//if(!event)

//return;

$("AddMark").style.top=document.body.clientHeight+document.body.scrollTop-200

$("AddMark").style.left=document.body.clientWidth-56;

$("AddMark").style.display='';

//(document.body.clientHeight-$("AddMark").offsetHeight)/2)+"px";

if($("MonthVoteTip"))

{

//$("MonthVoteTip").style.top=document.body.scrollTop+document.body.clientHeight-$("MonthVoteTip").offsetHeight+"px";

$("MonthVoteTip").style.top=getPosition($("AddMark")).y-$("AddMark").offsetHeight+"px";

}

}

}

functionAutoScroll()

{

window.onscroll=ScrollDiv;

window.onresize=ScrollDiv;

window.onload=ScrollDiv;

}

functiongetPosition(el)

{

for(varlx=0,ly=0;el!=null;lx+=el.offsetLeft,ly+=el.offsetTop,el=el.offsetParent);

return{x:lx,y:ly}

}

/*2007-11-28XuJian*/

//截取字符串包含中文处理

//(串,长度,增加...)

functionsubString(str,len,hasDot)

{

varnewLength=0;

varnewStr="";

varchineseRegex=/[^x00-xff]/g;

varsingleChar="";

varstrLength=str.replace(chineseRegex,"**").length;

for(vari=0;i<strLength;i++)

{

singleChar=str.charAt(i).toString();

if(singleChar.match(chineseRegex)!=null)

{

newLength+=2;

}

else

{

newLength++;

}

if(newLength>len)

{

break;

}

newStr+=singleChar;

}

if(hasDot&&strLength>len)

{

newStr+="...";

}

returnnewStr;

}

/*2007-10-2614:20GetStringLenth(includechinesecharacter)*/

functionGetStringLength(strObj)

{

returnstrObj.replace(/[^x00-xff]/g,"**").length;

}

functionaddMark(title,url){

try{

if(window.sidebar){

window.sidebar.addPanel(title,url,"");

}elseif(document.all){

window.external.AddFavorite(url,title);

}elseif(window.opera&&window.print){

returntrue;

}

}catch(e)

{

alert("您的浏览器安全设置不允许该项操作")

}

}

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新Javascript教程学习
    热门Javascript教程学习
    编程开发子分类