Js uses location. search to obtain parameters from the page, jslocation. search
This article mainly introduces how to use window. location. search to obtain parameters from the page.
Function GetQueryString (name) {var reg = new RegExp ("(^ | &)" + name + "= ([^ &] *) (& | $ )", "I"); var r = window. location. search. substr (1 ). match (reg); if (r! = Null) return (r [2]); return null ;}
Var sname = GetQueryString ("name"); if (sname! = Null) {var sname _ = decodeURIComponent (sname); alert (sname _);}
Test
Abcd.html? Name = xyz
Xyz should pop up
How can I accept parameters transmitted from the previous page in js?
Location. search can be used for processing.
How does js obtain url parameters to change the address of an image on the current page?
1. query location. search and obtain the string after the question mark;
2. Obtain the value of catelogID using regular expressions or other methods;
3. Use the id or tag to query the corresponding img element;
4. Set the src address of the img element to the address you have constructed;
5. The idea is like this.