This article mainly introduces how to get url-based value passing through javascript. The example analyzes two methods: string segmentation and regular expression analysis, in addition, I added a get value passing function for js to get URLs based on regular expression matching. For more information, see the example in this article. We will share this with you for your reference. The details are as follows:
Js:
Index.htm? Parameter 1 = value 1 & Parameter 2 = value 2 & Parameter 3 = data 3 & parameter 4 = value 4 &......
Static html file js reads url parameters and controls html page output based on the obtained html parameter values
I. string segmentation Analysis
Here is a JAVASCRIPT client solution for obtaining URL parameters with QUESTRING, equivalent to asp's request. querystring, PHP's $ _ GET
Function:
Then, we can call this function to obtain the corresponding parameter values:
Obtain the parameter with the same name in the url string.
Ii. Regular Expression Analysis
Function GetQueryString (name) {var reg = new RegExp ("(^ | &)" + name + "= ([^ &] *) (& | $ )", "I"); var r = window. location. search. substr (1 ). match (reg); if (r! = Null) return unescape (r [2]); return null;} alert (GetQueryString ("parameter name 1"); alert (GetQueryString ("parameter name 2 ")); alert (GetQueryString ("parameter name 3 "));
Supplement: js obtains the get value passing function of the url.
function getvl(name) { var reg = new RegExp("(^|\\?|&)"+ name +"=([^&]*)(\\s|&|$)", "i"); if (reg.test(location.href)) return unescape(RegExp.$2.replace(/\+/g, " ")); return "";};
Simple usage
For example, the url is http: // localhost/index. php? The qz value code in qz = ddddk is as follows:
The Code is as follows:
Getvl (bb); // you can
I hope this article will help you design JavaScript programs.