Javascript获取地址参数
内容摘要
<script>function getNewUrl(oldurl,paramname,pvalue){ var reg = new RegExp("(\\?|&)"+ paramname +"=([^&]*)(&|$)","gi"); var t=oldurl.
文章正文
<script>
function getNewUrl(oldurl,paramname,pvalue){
var reg = new RegExp("(\\?|&)"+ paramname +"=([^&]*)(&|$)","gi");
var t=oldurl.match(reg)[0];
var retxt=t.substring(0,t.indexOf("=")+1)+pvalue;
if(t.charAt(t.length-1)=='&') retxt+="&";
return oldurl.replace(reg,retxt);
}
alert(getNewUrl("....","p4","cxz"));
</script>
获取地址参数:
<script>
function aa(source, name)
{
var reg = new RegExp("(^|\\?|&)"+ name +"=([^&]*)(\\s|&|$)", "i");
if (reg.test(source)) return RegExp.$2; return "";
};
alert(aa("....", "temp"))
</script>
function getNewUrl(oldurl,paramname,pvalue){
var reg = new RegExp("(\\?|&)"+ paramname +"=([^&]*)(&|$)","gi");
var t=oldurl.match(reg)[0];
var retxt=t.substring(0,t.indexOf("=")+1)+pvalue;
if(t.charAt(t.length-1)=='&') retxt+="&";
return oldurl.replace(reg,retxt);
}
alert(getNewUrl("....","p4","cxz"));
</script>
获取地址参数:
<script>
function aa(source, name)
{
var reg = new RegExp("(^|\\?|&)"+ name +"=([^&]*)(\\s|&|$)", "i");
if (reg.test(source)) return RegExp.$2; return "";
};
alert(aa("....", "temp"))
</script>
代码注释