日期:2014-05-16  浏览次数:20462 次

javascript escape(),encodeURI(),decodeURI(),encodeURIComponent()区别

看下就明白了

原字符串:
<input name=keyword  size=100 value="http://www.yongfa365.com/"><br>
<input type=button onclick=codeurl() value="转换"><br>
encodeURI:(<font color=red>一般对网址javascript编码就用这个</font>)<input name=encodeURItest  size=100><br>
decodeURI:<input name=decodeURItest  size=100><br>
escape:<input name=escapetest  size=100><br>
encodeURIComponent:<input name=encodeURIComponenttest  size=100><br>

<script>
function codeurl()
{
encodeURItest.value = encodeURI(keyword.value)
decodeURItest.value = decodeURI(encodeURItest.value)
escapetest.value = escape(keyword.value)
encodeURIComponenttest.value = encodeURIComponent(keyword.value)
}
</script>
?