Get URL parameters through jquery and transcode
- 2020-03-30 03:45:29
- OfStack
Jquery gets the URL parameter and transcodes it. First, it constructs a regular expression object with the target parameter, matches the target parameter 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){
//Construct a regular expression object with the target parameters
var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
//Matching target parameters
var r = window.location.search.substr(1).match(reg);
//alert(r);
//Return parameter value
if (r!=null) return decodeURI(r[2]);
return null;
}
</script>
Test url: http://xxxx.html #63; Picture ="XXXX"&content=" hello!"