url 汉字乱码全方位解析

本文提供了一个简单的网页示例,展示了如何使用JavaScript进行编码转换,包括escape、unescape、encodeURIComponent及encodeURI等函数的应用。通过几个输入框和按钮,用户可以直观地看到不同编码方式的效果。

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

<html>
<head>
<script>
 
 var encode = escape('排行');
 alert(encode);
 alert('排行');
 function covert(){
  var z = document.getElementById('dd').value;
  document.getElementById('ecode').value = escape(z);
 }
 function uncovert(){
  var z = document.getElementById('dd1').value;
  document.getElementById('ecode1').value = unescape(z);
 }

function encodeURIComponent1(){
  alert('ddd');
  var z = document.getElementById('dd2').value;
  document.getElementById('ecode2').value = encodeURIComponent(z);
 }
function encodeURI1(){  
  var z = document.getElementById('dd3').value;
  document.getElementById('ecode3').value = encodeURI(z);
 }

function decodeURI1(){  
  var z = document.getElementById('dd4').value;
  document.getElementById('ecode4').value = decodeURI(z);
 }
 
</script>
</head>
<body>
<br/>
<input id = 'dd' type ="text" value ='' style="width:100px;"/>
<input id= "button" type ="button" value="转换" onclick="covert();"/>
<input id = 'ecode' type ="text" value =''/>
<br/>
<input id = 'dd1' type ="text" value =''/>
<input id= "unbutton" type ="button" value="反转换" onclick="uncovert();"/>
<input id = 'ecode1' type ="text" value =''/>
<br/>
<input id = 'dd2' type ="text" value =''/>
<input id= "unbutton1" type ="button" value="encodeURIComponent" onclick="encodeURIComponent1();"/>
<input id = 'ecode2' type ="text" value =''/>
<br/>
<input id = 'dd3' type ="text" value =''/>
<input id= "unbutton2" type ="button" value="encodeURI" onclick="encodeURI1();"/>
<input id = 'ecode3' type ="text" value =''/>
<br/>
<input id = 'dd4' type ="text" value =''/>
<input id= "unbutton3" type ="button" value="decodeURI" onclick="decodeURI1();"/>
<input id = 'ecode4' type ="text" value =''/>

 

<a id = "a1" href = "a.html?id=排行">a</a>
</body>
</html>

转载于:https://www.cnblogs.com/Impulse/archive/2011/11/07/2239626.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值