文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>备注:常用Js脚本

备注:常用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, '');
}

 

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载