标签:
JS获取地址栏制定参数值:
//获取URL参数的值
function getUrlParam(name){
var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if (r!=null) return unescape(r[2]); return null;
}
JS去除空字符:
String.prototype.trim=function()
{
return this.replace(/(^\s*)|(\s*$)/g,‘‘);
}
var str=" test ";
alert("["+str+"]"); // [ test ]
alert("["+str.trim()+"]"); // [test]
JS字符串格式化:
/** 格式化输入字符串**/
//用法: "hello{0}".format(‘world‘);返回‘hello world‘
String.prototype.format= function(){
var args = arguments;
return this.replace(/\{(\d+)\}/g,function(s,i){
return args[i];
});
}
var str = "hello{0}{1}".format(‘world‘,‘haha‘);
alert(str);
标签:
原文地址:http://www.cnblogs.com/loyung/p/4523728.html