JavaScript对URI的编码与解码

来源:互联网 发布:太古代之前 知乎 编辑:程序博客网 时间:2024/04/25 07:43
JavaScript对URI的编码与解码
<!--
编码:encodeURI(字符串)
解码:decodeURI(URI编码)
-->
<html>
<head>
<script language="javascript">
function str_to_url_encode()
{
  var str = document.test1.source.value;
  document.test1.result.value = encodeURI(str);
}
function url_to_str_decode()
{
  var str = document.test1.source.value;
  document.test1.result.value = decodeURI(str);
}
</script>
<body>
<form name="test1">
JavaScript对URI的编码与解码<BR>
<textarea name="source" style="width: 477pt; left: 77pt;"></textarea><br>
<textarea name="result" style="width: 477pt; left: 77pt;"></textarea><br>
<input type="button" value="编码" onclick="str_to_url_encode()">
<input type="button" value="解码" onclick="url_to_str_decode()">
</form>
</body>
</html> 
原创粉丝点击