url传参

A页面的某些参数需要传递给B页面

window.location.href = 'competition_console.html?compName='+encodeURI(compName)+'&compStyle='+compStyle+'&roundNum='+roundNum;

跳转到B页面时,传递参数。

B页面从url上获取参数:

function url_param(){
    var url = location.search; 
    var str = url.substr(1);  
            var strs= new Array();     
             strs = str.split('&');  
             param_name = decodeURI(strs[0].split("=")[1]);
             param_style = strs[1].split("=")[1];
             param_num = strs[2].split("=")[1];
}    

值得注意的是,如果传的参数有中文时需要进行编码及解码处理。

传参:encodeURI()进行编码;

取参:decodeURI()进行解码。

原文地址:https://www.cnblogs.com/lw5116/p/5804058.html