Improved JavaScript read URL parameters

Source: Internet
Author: User

<Br/> function geturlarg (seekarg) <br/> {<br/> var url = location. href; </P> <p> // use regular expressions to separate the parameters between the question mark and the well number, such as from the http://www.jb51.net/testjs.htm? P = 1 & t = 1 & U = 1 # In test, P = 1 & t = 1 & U = 1 <br/> If (rematch = URL. match (/\? ([^ #] + )#? /) <Br/>{< br/> var querystring = rematch [1]; <br/> // use the regular expression to press & OR = to split the string into an array, the args array contains the variable name and variable value in sequence, such as P, 1, t, 2, U, 24 <br/> var ARGs = querystring. split (// & | =/); <br/> // The ARG must be declared as an object. If only var Arg is written; when values are assigned later, an error is reported, indicating that the variable Arg is not defined. <br/> var Arg ={}; <br/> for (I = 0; I <br/> <input onclick = "runex ('runcode91614')" type = "button" value = "run code"> <input onclick = "docopy ('runcode91614 ') "type =" button "value =" Copy code "> <input onclick =" dosave (runcode91614) "type =" button "value =" Save code "> [Ctrl + A select all Note: To introduce external JS, refresh it before execution] </args>
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.