UTF-8編碼漢字互轉工具 Esp8266

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">&#x6587;&#x5B57;-1</textarea>
    <br />
    <input type="button" class="btn" onclick="ConvUtf(contents,this);"    value="&#x6587;&#x5B57; To UTF-8 &#x2193;">
    <input type="button" class="btn" onclick="ResChinese(result,this);" value="UTF-8 To &#x6587;&#x5B57; &#x2191;" 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>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章