Get URL parameters through jquery and perform transcoding. jqueryurl

Source: Internet
Author: User

Get URL parameters through jquery and perform transcoding. jqueryurl

Jquery obtains URL parameters and transcodes them. First, it constructs a regular expression object containing the target parameters, matches the target parameters, and returns the parameter values.

The Code is as follows:

<Script type = "text/javascript"> $ (document ). ready (function () {var pic_url = getUrlParam ("picture"); $ ("# childpic "). attr ("src", pic_url); var content = getUrlParam ("content "); $ ("# content" pai.html ("<B>" + content + "</B>") ;}; function getUrlParam (name) {// construct a regular expression object var reg = new RegExp ("(^ | &)" + name + "= ([^ &] *) containing the target parameter (& | $) "); // match the target parameter var r = window. location. search. substr (1 ). match (reg); // alert (r); // return the parameter value If (r! = Null) return decodeURI (r [2]); return null ;}</script>

Test url: http://xxxx.html? Picture = "XXXX" & content = "Hello! "


Determine the url parameter obtained by jquery and change the id value

Function parse_url (url) {if (url. lastIndexOf ('? ') = 0) {var str = url. substring (url. lastIndexOf ('? ') + 1, url. length); var arr = str. split ('&'); var parames = []; for (var I = 0; I <arr. length; I ++) {parames [arr [I]. split ('=') [0] = arr [I]. split ('=') [1];} return parames;} var type = parse_url (location. search); if (type) {if (type ['lang '] = 'Fr') {document. getElementById ('id '). innerHTML = 'good thanks '; document. getElementById ('id1 '). innerHTML = 'good thanks ';} the code should be placed behind the two elements id: 'id' and 'id1'

That is to say, when executing this code, make sure that the page elements are loaded.


How does jquery obtain the parameter values in the URL?

Jquery uses JS to get the url. window. location. href
 

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.