首页 > 技术文章 > js unicode转中文 方案概述联网LED照明方案可执行全部的DALI 和

qq364735538 2019-01-25 11:58 原文

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
    var str ='&#26041;&#26696;&#27010;&#36848;&#32852;&#32593;LED&#29031;&#26126;&#26041;&#26696;&#21487;&#25191;&#34892;&#20840;&#37096;&#30340;DALI &#21644; DMX512A&#21327;&#35758;&#12290;&#35813;&#26041;&#26696;&#21253;&#25324;LED&#39537;&#21160;&#26495;'
    function reconvert(str){ 
		str = str.replace(/(\\u)(\w{1,4})/gi,function($0){ 
			return (String.fromCharCode(parseInt((escape($0).replace(/(%5Cu)(\w{1,4})/g,"$2")),16))); 
		}); 
		str = str.replace(/(&#x)(\w{1,4});/gi,function($0){ 
			return String.fromCharCode(parseInt(escape($0).replace(/(%26%23x)(\w{1,4})(%3B)/g,"$2"),16)); 
		}); 
		str = str.replace(/(&#)(\d{1,6});/gi,function($0){ 
			return String.fromCharCode(parseInt(escape($0).replace(/(%26%23)(\d{1,6})(%3B)/g,"$2"))); 
		}); 
		
		return str; 
	}
    var a = reconvert(str)
    console.log(a)
    </script>
</body>
</html>

  

推荐阅读