首页 > Web开发 > 详细

js对特殊字符转义、时间格式化、获取URL参数

时间:2016-01-09 22:53:24      阅读:422      评论:0      收藏:0      [点我收藏+]
/*特殊字符转义*/
function replace_html(str) {
var str = str.toString().replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, ‘&quot;‘);
return str;
}
/*
*时间格式化
*例子:time = new Date().Format("yyyy-MM-dd hh:mm:ss");
*/
Date.prototype.Format = function (result) {
var o = {
"M+": this.getMonth() + 1, //month
"D+": this.getDate(), //day
"h+": this.getHours(), //hours
"m+": this.getMinutes(), //minutes
"s+": this.getSeconds(), //seconds
"q+": Math.floor((this.getMonth() + 3) / 3), // season
"S": this.getMilliseconds() //milliseconds
};
if (/(Y+)/.test(result)) {
result = result.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
}
for (var k in o){
if (new RegExp("(" + k + ")").test(result)) {
result = result.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
}
}
return result;
};


/*
*获取URL参数
*/
function getQueryString(key){
var reg = new RegExp("(^|&)"+ key +"=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if(r!=null){
return unescape(r[2]);
}
return null;
}

 

js对特殊字符转义、时间格式化、获取URL参数

原文:http://www.cnblogs.com/zzp5980/p/5117386.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!