备注:常用Js脚本
时间:2010-08-30 来源:欣静赏悦
一、Cookies操作:
代码function clearCookie() {
var now = new Date();
var yesterday = new Date(now.getTime() - 1000 * 60 * 60 * 24);
this.setCookie('co'+this.obj, 'cookieValue', yesterday);
this.setCookie('cs'+this.obj, 'cookieValue', yesterday);
this.setCookie('keep', 'cookieValue', yesterday);
};
function setCookie(cookieName, cookieValue, expires, path, domain, secure) {
document.cookie =
escape(cookieName) + '=' + escape(cookieValue)
+ (expires ? '; expires=' + expires.toGMTString() : '')
+ (path ? '; path=' + path : '')
+ (domain ? '; domain=' + domain : '')
+ (secure ? '; secure' : '');
};
function getCookie(cookieName) {
var cookieValue = '';
var posName = document.cookie.indexOf(escape(cookieName) + '=');
if (posName != -1) {
var posValue = posName + (escape(cookieName) + '=').length;
var endPos = document.cookie.indexOf(';', posValue);
if (endPos != -1) cookieValue = unescape(document.cookie.substring(posValue, endPos));
else cookieValue = unescape(document.cookie.substring(posValue));
}
return (cookieValue);
};
二、浏览器多语言切换:
代码function ChangeLang() {
if(document.documentElement.lang == 'en-us') {
javascript:OnLangSelectionChange(2052);
} else {
javascript:OnLangSelectionChange(1033);
}
}
function OnLangSelectionChange(value)
{
var today = new Date();
var oneYear = new Date(today.getTime() + 365 * 24 * 60 * 60 * 1000);
var url = window.location.href;
document.cookie = 'lcid=' + value + ';path=/;expires=' + oneYear.toGMTString();
window.location.href = url;
}
三、正则表达式颜色值:
代码function checkColor(str) {
var pattern = /^#[0-9a-fA-F]{6}$/;
if (str.match(pattern) == null)
return null;
else
return str;
}
四、正则表达式空值:
function replaceSpace(str) {
if (str == null)
return null;
else
return str.replace(/\s/g, '');
}
相关阅读 更多 +