首页 > Web开发 > 详细

url传参

时间:2016-08-24 19:06:20      阅读:264      评论:0      收藏:0      [点我收藏+]

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()进行解码。

 

url传参

原文:http://www.cnblogs.com/lw5116/p/5804058.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!