这个是封装好的方法:

function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if ( r != null ){
       return unescape(r[2]);
    }else{
       return null;
    } 
 }

如果有中文参数时,会出现乱码,解决方法就是:将解码方式unscape换为decodeURI

原因:浏览器会将url中的中文参数进行encodeURI编码,所以要通过js使用decodeURI进行解码

本文转至园友 codefly-sun 感谢

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-05-27
  • 2022-12-23
  • 2022-12-23
  • 2021-11-20
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-22
  • 2022-12-23
  • 2021-11-14
  • 2021-08-26
相关资源
相似解决方案