当前位置: 代码迷 >> 综合 >> url传中文参数乱码
  详细解决方案

url传中文参数乱码

热度:71   发布时间:2024-01-21 01:13:34.0

encodeURI 编码 解码

encodeURI();

编码 解码都是这个方法

实例:

// 编码$(".index-search").bind('keydown',function(event){var text = encodeURI($(this).val());if(event.keyCode == "13") {window.open("search-list.html?keyword="+text);}})//解码var url = window.location.href;console.log(window.location.href);function getCaption(obj){var index=obj.lastIndexOf("\=");    //获取-后边的字符串obj=obj.substring(index+1,obj.length);//  console.log(obj);return obj;}var keyWord = getCaption(url);keyWord = decodeURI(keyWord);

  相关解决方案