Home > Article > Web Front-end > Get URL parameters and transcode them through jquery_jquery
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>
Test url: http://xxxx.html?picture="XXXX"&content="Hello!"