[英]How to encode String to UTF-8 directly in JavaScript?
I must encode a String to UTF-8, in order that the German Umlaut to be correctly displayed. 我必须将字符串编码为UTF-8,以便正确显示德语Umlaut。
I have the following JavaScript: 我有以下JavaScript:
.append( "<a><div class='autocompleteName'>" + itemLabel + " (" + item.id + ")</div></a>")
I need to encode itemLabel variable to UTF-8. 我需要将itemLabel变量编码为UTF-8。
This Java line of code I need to be able to execute in JavaScript: 我需要能够在JavaScript中执行以下Java代码行:
itemLabel = new String(itemLabel.getBytes("ISO-8859-1"), "utf-8");
Does anyone know how? 有人知道吗?
Thank you! 谢谢!
I found this on http://www.w3schools.com/tags/att_script_charset.asp 我在http://www.w3schools.com/tags/att_script_charset.asp上找到了
set your script tag as 将您的脚本标签设置为
<script src="myscripts.js" charset="UTF-8"></script>
maybe it works 也许有效
如何将此元标记放在html文件的开头。
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.