Home > Web Front-end > JS Tutorial > body text

js tool to convert characters to UTF-8 characters_javascript skills

WBOY
Release: 2016-05-16 18:24:57
Original
1574 people have browsed it

在下面的文本框中输入中文文字,按“转化”,即可将其转化为UTF-8字符。
再按“还原”,即可将其还原为简体中文。

<script> var mode="zhuan"; function encode(obj,btn){ if(mode=="zhuan"){ obj.value=obj.value.replace(/[^\u0000-\u00FF]/g,function($0){return escape($0).replace(/(%u)(\w{4})/gi,"&#x$2;")}); btn.value="还原"; mode="huan"; }else{ obj.value=unescape(obj.value.replace(/&#x/g,'%u').replace(/;/g,'')); btn.value="转化"; mode="zhuan"; } } </script>


[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!