javascript 獲取url參數(shù)的正則表達(dá)式(用來獲取某個參數(shù)值)
更新時間:2010年01月17日 22:02:31 作者:
javascript 傳多個參數(shù)的正則表達(dá)式(用來獲取某個參數(shù)值) ,腳本之家之前發(fā)布通過函數(shù)獲取url參數(shù)的代碼不是正則表達(dá)式。
例子:
//javascript傳參數(shù)(多個)
var url = "B.aspx?txtA="+document.getElementById("txtName").value;
url +="&txtB="+document.getElementById("txtAge").value;
window.open(url,'xWindow','width=640,height=400,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,top=250,left=430');
//B.aspx目標(biāo)頁取得
<scirpt language='javascirpt'>
<!--
function GetStringValue()
{
String.prototype.getQueryString = function(name)//name 是URL的參數(shù)名字
{
var reg = new RegExp("(^|&|\\?)"+ name +"=([^&]*)(&|$)"), r;
if (r=this.match(reg)) return unescape(r[2]); return null;
};
//直接可以傳參數(shù)名 就可以 得到參數(shù)的值
alert(window.location.href.getQueryString("txtA")+window.location.href.getQueryString("txtB"));
}
-->
</scirpt>
window.open和 window.location區(qū)別:
window.open是打開新窗口
window.location是將本頁替換了,也就是定位
onclick="javascript:window.location.href='XXXX.aspx';"
JavaScript URL參數(shù)讀取改進(jìn)版
http://www.fzitv.net/article/17116.htm
//javascript傳參數(shù)(多個)
var url = "B.aspx?txtA="+document.getElementById("txtName").value;
url +="&txtB="+document.getElementById("txtAge").value;
window.open(url,'xWindow','width=640,height=400,status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,top=250,left=430');
//B.aspx目標(biāo)頁取得
復(fù)制代碼 代碼如下:
<scirpt language='javascirpt'>
<!--
function GetStringValue()
{
String.prototype.getQueryString = function(name)//name 是URL的參數(shù)名字
{
var reg = new RegExp("(^|&|\\?)"+ name +"=([^&]*)(&|$)"), r;
if (r=this.match(reg)) return unescape(r[2]); return null;
};
//直接可以傳參數(shù)名 就可以 得到參數(shù)的值
alert(window.location.href.getQueryString("txtA")+window.location.href.getQueryString("txtB"));
}
-->
</scirpt>
window.open和 window.location區(qū)別:
window.open是打開新窗口
window.location是將本頁替換了,也就是定位
onclick="javascript:window.location.href='XXXX.aspx';"
JavaScript URL參數(shù)讀取改進(jìn)版
http://www.fzitv.net/article/17116.htm
相關(guān)文章
js正則表達(dá)式實現(xiàn)數(shù)字每隔四位用空格分隔代碼
這篇文章主要介紹了js正則表達(dá)式實現(xiàn)數(shù)字每隔四位用空格分隔代碼,需要的朋友可以參考下2016-12-12
JavaScript正則表達(dá)式校驗非零的正整數(shù)實例
本文分享了JavaScript正則表達(dá)式(^[1-9]\d*$ 或 ^([1-9][0-9]*){1,3}$ 或 ^\+?[1-9][0-9]*$)校驗非零的正整數(shù)實例代碼,代碼簡單易懂,需要的朋友可以看下2016-12-12
常用的正則表達(dá)式大全(數(shù)字、字符、固定格式)
正則表達(dá)式(regular expression)描述了一種字符串匹配的模式,可以用來檢查一個串是否含有某種子串、將匹配的子串做替換或者從某個串中取出符合某個條件的子串等。本文給大家分享常用的正則表達(dá)式大全(數(shù)字、字符、固定格式),感興趣的小伙伴一起學(xué)習(xí)吧2016-04-04

