fmfsaisai
游民
积分:20

encodeURIComponent无效

str = "//content#
";//原始字符串
str = encodeURIComponent(str);

结果还是
//content#

没有进行任何编码...

dingshili
游民
积分:40

<html>
<script>
function getssList()
	{
	    str = "//content#";//原始字符串
		str = encodeURIComponent(str);
		alert(str);
	}
</script>
<body>
<input type="button" name="sslist" value="转化" onclick="getssList()">
</body>
</html>

在网页做了测试没有问题

dingshili
游民
积分:40

在openface开发环境下,我测试了encodeURIComponent函数都不能转化(可能不支持),encodeURI 、escape方法可以转化,但是有转化的字符限制
最多使用的应为encodeURIComponent,它是将中文、韩文等特殊字符转换成utf-8格式的url编码,所以如果给后台传递参数需要使用encodeURIComponent时需要后台解码对utf-8支持(form中的编码方式和当前页面编码方式相同)

escape不编码字符有69个:*,+,-,.,/,@,_,0-9,a-z,A-Z

encodeURI不编码字符有82个:!,#,$,&,',(,),*,+,,,-,.,/,:,;,=,?,@,_,~,0-9,a-z,A-Z

encodeURIComponent不编码字符有71个:!, ',(,),*,-,.,_,~,0-9,a-z,A-Z