当前位置:主页 > 查看内容

javascript 获取url参数的正则表达式(用来获取某个参数值)

发布时间:2021-07-01 00:00| 位朋友查看

简介:例子: //javascript传参数(多个) 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,locati……
例子:
//javascript传参数(多个)
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目标页取得
复制代码 代码如下:

<scirpt language='javascirpt'>
<!--
function GetStringValue()
{
String.prototype.getQueryString = function(name)//name 是URL的参数名字
{
var reg = new RegExp("(^|&|\\?)"+ name +"=([^&]*)(&|$)"), r;
if (r=this.match(reg)) return unescape(r[2]); return null;
};
//直接可以传参数名 就可以 得到参数的值
alert(window.location.href.getQueryString("txtA")+window.location.href.getQueryString("txtB"));
}
-->
</scirpt>

window.open和 window.location区别:
window.open是打开新窗口
window.location是将本页替换了,也就是定位
onclick="javascript:window.location.href='XXXX.aspx';"
JavaScript URL参数读取改进版
https://www.jb51.net/article/17116.htm

原文链接:https://m.jb51.net/article/21853.htm
本站部分内容转载于网络,版权归原作者所有,转载之目的在于传播更多优秀技术内容,如有侵权请联系QQ/微信:153890879删除,谢谢!
上一篇:PHP 正则表达式后面接的/isU, /is, /s含义 下一篇:没有了

推荐图文


随机推荐