UTF-8編碼漢字互轉工具
編寫esp8266 web 文件常用到UTF-8編碼漢字互轉
附上html工具 代碼
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>UTF-8轉換工具</title>
<style type="text/css">
.form-control {width:360px; margin: 10px auto; }
.btn {font-family:Tahoma; font-size:15px; background: blue; color:white;
width: 150px;
line-height: 50px;
text-align: center;
font-weight: 700;
color: #FFF;
border-radius: 8px;
border: 0px solid #FFF;
background: darkcyan;
font-size: 15px;
}
</style>
<body>
<center>
<form name="code">
<textarea id="contents" name="contents" class="form-control" rows="8">文字-1</textarea>
<br />
<input type="button" class="btn" onclick="ConvUtf(contents,this);" value="文字 To UTF-8 ↓">
<input type="button" class="btn" onclick="ResChinese(result,this);" value="UTF-8 To 文字 ↑" style="background: royalblue" >
<br />
<textarea id="result" name="result" class="form-control" rows="8">UTF8-2</textarea>
</form>
</center>
<script>
function ConvUtf(obj,btn){
document.getElementById("result").value=obj.value.replace(/[^\u0000-\u00FF]/g,function($0){return escape($0).replace(/(%u)(\w{4})/gi,"&#x$2;")});
document.querySelector("#result").select();
document.execCommand('copy');
}
function ResChinese(obj,btn){
document.getElementById("contents").value=unescape(obj.value.replace(/&#x/g,'%u').replace(/;/g,''));
document.querySelector("#contents").select();
document.execCommand('copy');
}
</script>
</body>
</html>