1方法:
html中通过url地址传参及获取参数: var url = document.location.toString();//获取url地址 var urlParmStr = url.slice(url.indexOf('?')+1);//获取问号后所有的字符串 var arr = urlParmStr.split('&');//通过&符号将字符串分割转成数组 var courseId = arr[0].split("=")[1];//获取数组中第一个参数 var unit_title=arr[1].split("=")[1];//第二个参数 unit_title=decodeURI(unit_title);//转码将解码方式unscape换为decodeURI,将中文参数获取 console.log(unit_title);
2方法:
<script type="text/javascript" charset="utf-8">
function getUrlParameter(name){
name = name.replace(/[]/,"\[").replace(/[]/,"\[").replace(/[]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec(window.parent.location.href);
if( results == null )
return "";
else {
return results[1];
}
};
</script>
调用部分:
<script charset="utf-8">
document.title = decodeURI(getUrlParameter("title"));
</script>