Home > Web Front-end > JS Tutorial > Get URL parameters and transcode them through jquery_jquery

Get URL parameters and transcode them through jquery_jquery

WBOY
Release: 2016-05-16 16:39:25
Original
1760 people have browsed it

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 value

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").html("<b>"+content+"</b>"); 
}); 
function getUrlParam(name){ 
//构造一个含有目标参数的正则表达式对象 
var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)"); 
//匹配目标参数 
var r = window.location.search.substr(1).match(reg); 
//alert(r); 
//返回参数值 
if (r!=null) return decodeURI(r[2]); 
return null; 
} 
</script>
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template