你可以使用escape来实现,注意的是参数中不能包括如下特殊字符:* @ - _ + . / eg.
window.replace('aaa.asp?b=escape("~#&$%%^#(&c=1")');描述:
escape 函数是一个顶级 JavaScript 函数,并不与任何对象关联。使用 escape 和 unescape 函数可以将属性值手工添加到 URL 中。
escape 函数编码指定字符串中的特定字符,并返回新字符串。它编码空格、标点符号及其它不位于 ASCII 字母表的字符.
window.replace('aaa.asp?b=escape("~#&$%%^#(&c=1")');描述:
escape 函数是一个顶级 JavaScript 函数,并不与任何对象关联。使用 escape 和 unescape 函数可以将属性值手工添加到 URL 中。
escape 函数编码指定字符串中的特定字符,并返回新字符串。它编码空格、标点符号及其它不位于 ASCII 字母表的字符.
有没有什么办法可以实现使用所有的特殊字符?
<!--
function mm(s)
{
var str = s.replace(/%/g, "%25").replace(/\+/g, "%2B").replace(/\s/g, "+"); // % + \s
str = str.replace(/-/g, "%2D").replace(/\*/g, "%2A").replace(/\//g, "%2F"); // - * /
str = str.replace(/\&/g, "%26").replace(/!/g, "%21").replace(/\=/g, "%3D"); // & ! =
str = str.replace(/\?/g, "%3F").replace(/:/g, "%3A").replace(/\|/g, "%7C"); // ? : |
str = str.replace(/\,/g, "%2C").replace(/\./g, "%2E").replace(/#/g, "%23"); // , . #
return str;
}
var s = "aaa.asp?"+ mm("b=~#&$%%^#(&c=1");
alert(s); //这样转换过之后就没有任何问题了.
//-->
</SCRIPT>