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