您的位置:首页 > 其它

ajax中get提交的时候改变参数的编码

2016-02-29 11:16 260 查看
function transUrlParaCode(para){
var s = para;
if (para != null){
s = para.replaceAll("%", "%25");
s = s.replaceAll(" ", "%20");
s = s.replaceAll("/", "%2F");
s = s.replaceAll("#", "%23");
s = s.replaceAll("\\+", "%2B");
s = s.replaceAll("\\?", "%3F");
s = s.replaceAll("&", "%26");
s = s.replaceAll("\\=", "%3D");
}
return s;
}


jquery对查询到的数据中的非法字符进行转义,然后使用转义后的字符当作id使用。防止id中有些符号导致不能作为id使用。

//jquery 中对特殊字符转义

function jqTrans(str){
if(str.length>0&&str.trim()!=""){
str=str.replaceAll(" ","");
str=str.replaceAll("#","");
str=str.replaceAll("\\$","");
str=str.replaceAll("=","");
str=str.replaceAll("&","");
str=str.replaceAll("@","");
}
return str;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: