JavaScript对URI的编码与解码

本文介绍了一个简单的JavaScript程序,用于实现URI编码与解码的功能。通过两个按钮操作,可以将输入的字符串进行URI编码或者解码,并显示结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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> 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值