<p>
<script type="text/javascript">// <![CDATA[
var decToHex = function(str) {
var res=[];
for(var i=0;i < str.length;i++)
res[i]=("00"+str.charCodeAt(i).toString(16)).slice(-4);
return "\\u"+res.join("\\u");
}
var hexToDec = function(str) {
str=str.replace(/\\/g,"%");
return unescape(str);
}
var bianma=function()
{
document.getElementById('code12').value=decToHex(document.getElementById('code11').value);
}
var jiema=function()
{
document.getElementById('code22').value=hexToDec(document.getElementById('code21').value);
}
// ]]></script>
</p>
<p><textarea id="code11" style="width: 423px; height: 98px;" rows="5" cols="50"></textarea> <br /><input onclick="bianma()" type="button" value="编码" /> <br /><textarea id="code12" style="width: 422px; height: 119px;" rows="5" cols="44"></textarea></p>
<p><br /> <textarea id="code21" style="width: 423px; height: 136px;" rows="7" cols="50"></textarea><br /><input onclick="jiema()" type="button" value="解码" /></p>
<p><textarea id="code22" style="width: 439px; height: 132px;" rows="4" cols="46"></textarea> </p>
![](https://img2024.cnblogs.com/blog/35695/202408/35695-20240826070647288-243310440.jpg)