js工具方法

function GetObj(s)
{
return document.getElementById(s)
}
function SetCookie(name, value)
{
var expdate = new Date();
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
if(expires!=null) expdate.setTime(expdate.getTime() + ( expires * 1000 ));
document.cookie = name + "=" + escape (value) +((expires == null) ? "" : ("; expires="+ expdate.toGMTString()))
+((path == null) ? "" : ("; path=" + path)) +((domain == null) ? "" : ("; domain=" + domain))
+((secure == true) ? "; secure" : "");
}
function GetCookie(sName)
{
var aCookie = document.cookie.split("; ");
for (var i=0; i < aCookie.length; i++)
{
   var aCrumb = aCookie[i].split("=");
   if (sName == aCrumb[0])
    return unescape(aCrumb[1]);
}
return null;
}
function GetUserName()
{
var uid=GetCookie("userid");
var unm=GetCookie("jcusername");
if(uid==null||uid=="")
{
// GetObj('liwlc').style.display="none";
GetObj('lilg').style.display="";
GetObj('lirg').style.display=""
}
else
{
if(unm!=null&&unm!=undefined&&unm!="")
{
GetObj('lilg').style.display="none";
GetObj('lirg').style.display="none";
var wlc=GetObj('liwlc');
var wlc2=GetObj('liwlc2');
var wlc3=GetObj('liwlc3');
var url=document.location;
wlc.style.display="";
wlc.innerHTML= "<strong>"+unm+"</strong>"+"&nbsp;您好!&nbsp;"
wlc2.innerHTML="<a href='http://www.jctrans.com/office/sywl_ly_sd.aspx?ly=sd' class='a1'>我的留言</a>";
wlc3.innerHTML="<a href='http://www.jctrans.com/office/login.html?flag=1&forward="+url+"' class='a2'>退出登录</a>"
}
else
{
GetObj('liwlc').style.display="none";
GetObj('liwlc2').style.display="none";
GetObj('liwlc3').style.display="none";
GetObj('lilg').style.display="";
GetObj('lirg').style.display=""
}
}
}
function Trim(inputString)
{
return inputString.replace(/^ +/,"").replace(/ +$/,"");
}
function RemoveSp(str)
{
var re =/(!)|(@)|(&amp)|(#)|,|'|(\^)|(\$)|(\.)|(\*)|(\")|(\|)|(\-)/gim
str = str.replace(re,"");
return str;
}
function TxtString(obj,s)
{
  var os = Trim(obj.value);
if(os==s){obj.value='';}
else if(os==''){ obj.value=s;}
}
function ReTxtString(obj,s)
{
var os = Trim(obj.value);
if(os==s){return "";}
else{return obj.value;}
}
function Showweek()
  {
  var now = new Date()
  if (now.getDay() == 0){return ("星期日");}
  if (now.getDay() == 1){return ("星期一");}
  if (now.getDay() == 2){return ("星期二");}
  if (now.getDay() == 3){return ("星期三");}
  if (now.getDay() == 4){return ("星期四");}
  if (now.getDay() == 5){return ("星期五");}
  if (now.getDay() == 6){return ("星期六");}
  }
  function Showdate()
  {
  var now = new Date()
  var year = now.getYear()
  var month = now.getMonth()+1
  var day = now.getDate()
  return year+"年"+month+"月"+day+"日"
  }

//去掉字符串首尾的空格
String.prototype.trim= function() 

    // 用正则表达式将前后空格 
    // 用空字符串替代。 
    return this.replace(/(^\s*)|(\s*$)/g, ""); 
}

你可能感兴趣的:(正则表达式,OS,prototype)