url传参和解决中文乱码

在A页面把参数传给B页面

index.html?name="张三"

在B页面接收(js)

    function getQueryString(name) {
         var result = window.location.search.match(new RegExp("[?&]" + name
         + "=([^&]+)", "i"));
         if (result == null || result.length < 1) {
         return "";
         }
         return result[1];
    
         }

  var name = getQueryString("name");
  alert(name);

显示中文是乱码,需要改为

var name = decodeURIComponent(getQueryString("name"));

就可以了

原文地址:https://www.cnblogs.com/Arisf/p/15169918.html