JS URL传递中文参数时出现乱码的处理
在浏览器中显示的地址是这样的:
但是按F12调试的时候的地址却变化掉了:
这个肯定是是因为浏览器对url路径默认编码了。这个问题是在我们去取值的时候,得到的就是后面那一大串稀奇古怪的东西。得不到我们想要的值。怎么办呢?这里写出来的只是自己的解决方法,也许不能通用,跟大家分享下,有更好的方法,告我一声。
//得到url中的值
function request(paras){
var url = location.href;
var paraString = url.substring(url.indexOf("?")+1,url.length).split("&");
var paraObj = {};
for (var i=0; j=paraString[i]; i++){
paraObj[j.substring(0,j.indexOf("=")).toLowerCase()] = j.substring(j.indexOf("=")+1,j.length);
}
var returnValue = paraObj[paras.toLowerCase()];
if(typeof(returnValue)=="undefined"){
return "";
}else{
return returnValue;
}
} function getHys(){
if(request('hys') !=''){
//decodeURL 将传递方的中文又解码
var hys=decodeURI(request('hys'));
var select =document.getElementById('nybgs');
var selectValue="";
for(var i=0;i<select.options.length;i++){
selectValue=select.options[i].value;
if(document.getElementById('nybgs').options[i].value==hys){
document.getElementById('nybgs').selectedIndex = i;
}
}
}
}
request方法是取地址中的参数的方法,decodeURI()方法就是将传递方的中文又解码。
在火狐和360和IE8中测试过,都没问题,不知道大家有没有其他更好的办法?
JS URL传递中文参数时出现乱码的处理的更多相关文章
- JS URL传中文参数引发的乱码问题
今天的项目中碰到了一个乱码问题,从JS里传URL到服务器,URL中有中文参数,服务器里读出的中文参数来的全是“?”,查了网上JS编码相关资料得以解决. 解决方法一: 1.在JS里对中文参数进行两次转码 ...
- Java中url传递中文参数取值乱码的解决方法
java中URL参数中有中文值,传到服务端,在用request.getParameter()方法,得到的常常会是乱码,这将涉及到字符解码操作. 方法一: http://xxx.do?ptname=’我 ...
- HTML的Get方法URL传递中文参数,解决乱码问题
本例中有使用JQuery. 资料参考:http://www.cnblogs.com/babycool/p/3169058.html 发送的HTML页面代码: <!DOCTYPE html> ...
- C#Url传递中文参数时解决方法
原文发布时间为:2008-11-05 -- 来源于本人的百度文章 [由搬家工具导入] 1.设置web.config文件。<system.web> <globalization req ...
- url中传递中文参数时的转码与解码
URL传递中文参数时的几种处理方式,总结如下: 1.将字符串转码:newString(“xxxxx”.getBytes("iso-8859-1"),"utf-8" ...
- 通过URL传递中文参数的乱码处理
环境:web.xml中配置了 <filter> <filter-name>encodingFilter</filter-name> <filter-class ...
- url 传递中文参数乱码问题的终极解决方法。
估计很多人在做web开发的时候,都会碰到过url传递中文参数,有时候会出现乱码的问题,但有些项目或者环境,又不会有问题.当遇到乱码的时候,上网找了很多解决方案,比如: 页面设置它的编码方式,改成utf ...
- URL传递中文参数,大坑一枚,Windows与Linux效果竟然不一致(两种解决方法)
下午,计划2个小时搞定,个人官网第6次升级,就可以干点轻松的事了,结果,下午多搞了2个小时,晚上又搞了2个小时,才搞定. 最后一个世界难题是,URL传递中文参数. 问题大致是这么出现的:我为" ...
- asp.net URL传递中文参数System.Web.HttpUtility.UrlEncode与Server.UrlEncode的区别
asp.net URL传递中文参数System.Web.HttpUtility.UrlEncode与Server.UrlEncode的区别(一) HttpUtility.UrlEncode 方法: 对 ...
随机推荐
- 下载Spring的jar包的方法
- bzoj3262: 陌上花开(树套树)
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #i ...
- POJ2001 Shortest Prefixes
Description A prefix of a string is a substring starting at the beginning of the given string. The p ...
- malware analysis、Sandbox Principles、Design && Implementation
catalog . 引言 . sandbox introduction . Sandboxie . seccomp(short for secure computing mode): API级沙箱 . ...
- SQLite Learning、SQL Query Optimization In Multiple Rule
catalog . SQLite简介 . Sqlite安装 . SQLite Programing . SQLite statements 1. SQLite简介 SQLite是一款轻型的数据库,是遵 ...
- J-link烧写brjtag工具
J-Link用的山寨货,不知道山寨了几代的那种....用的STM32F103C8T6的小板也是山寨了好几代那种,才25块钱...好在能用,J-Link用segger公司的软件能识别,也能找到CPU,板 ...
- centos+nginx从零开始配置负载均衡
nginx负载均衡的理解 nginx是一个轻量级的.高性能的webserver,他主要可以干下面两件事: 作为http服务器(和apache的效果一样) 作为反向代理服务器实现负载均衡 现在nginx ...
- Codeforces Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) A. Checking the Calendar(水题)
传送门 Description You are given names of two days of the week. Please, determine whether it is possibl ...
- Jboss7.1 加入realm auth认证 bootsfaces 美化的登录页面
jboss-as-7.1.1.Final\standalone\configuration: 1, standalone.xml中 <security-domains>标签里面添加: &l ...
- oracle--知识点汇总1
同义词: -- e是scott.emp表的临时别名 select e.* from (select * from scott.emp) e; --创建私有同义词 create synonym myem ...