Js uses location. search to obtain parameters from the page, jslocation. search

Source: Internet
Author: User

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.
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.