js截取地址栏参数

来源:互联网 发布:windows 7彩蛋 编辑:程序博客网 时间:2024/06/06 20:05


function gup(name) {   
    var regexS = "[\\?&]"+name+"=([^&#]*)";  //匹配name参数对  
        var regex = new RegExp( regexS );
        var results = regex.exec( window.location.href );//过滤超链接  
         if( results == null ) {   
             return "";   
   } else {  
          return results[1];    
   }   
 }


使用方法:

a页面的js

window.location = 'b.html?name=张三';


b页面的js

var name = gup(“name”);即可得到传过来的参数

原创粉丝点击