Example of jquery getting URL parameters and transcoding, jqueryurl
Using jquery to obtain URL parameters and transcode them, I personally think it is good because sometimes garbled characters are not transcoded.
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.
Code:
<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>") ;}); // www. jbxue. comfunction getUrlParam (name) {// construct a regular expression object with the target parameter var reg = new RegExp ("(^ | &) "+ name +" = ([^ &] *) (& | $) "); // match the target parameter var r = window. location. search. substr (1 ). match (reg); // ale Rt (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