JavaScript gets the regular expression of URL parameter (used to get a parameter value)

Time:2021-4-29

example:
//JavaScript parameters (multiple)
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 target page

Copy codeThe code is as follows:
<scirpt language=’javascirpt’>
<!–
function GetStringValue()
{
String. Prototype. Getquerystring = function (name) / / name is the parameter name of the URL
{
var reg = new RegExp(“(^|&|\\?)”+ name +”=([^&]*)(&|$)”), r;
if (r=this.match(reg)) return unescape(r[2]); return null;
};
//You can get the parameter value by passing the parameter name directly
alert(window.location.href.getQueryString(“txtA”)+window.location.href.getQueryString(“txtB”));
}
–>
</scirpt>

Difference between window.open and window.location:
Window. Open is to open a new window
Window. Location is the replacement of this page, that is, location
onclick=”javascript:window.location.href=’XXXX.aspx’;”
JavaScript URL parameter reading improved version
https://www.jb51.net/article/17116.htm

Recommended Today

Looking for frustration 1.0

I believe you have a basic understanding of trust in yesterday’s article. Today we will give a complete introduction to trust. Why choose rust It’s a language that gives everyone the ability to build reliable and efficient software. You can’t write unsafe code here (unsafe block is not in the scope of discussion). Most of […]