阿拉伯字符在JavaScript中无法正确显示 [英] Arabic characters doesn't show properly in JavaScript
本文介绍了阿拉伯字符在JavaScript中无法正确显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我在JavaScript中添加阿拉伯字符时,它没有正确显示。我猜这是一个ASCII问题。有什么建议吗?
When I add a Arabic characters in JavaScript, It does not showed properly. I guess that is an ASCII problem. Any suggestions?
JavaScript
document.getElementById('div-msg').innerText = "اسم المستخدم لا يمكن أن تترك فارغة";
HTML
<html>
<head>
</head>
<body>
<div id="div-msg" style="width:100%; height:200px; background:yellow">
</div>
<script type="text/javascript">
document.getElementById('div-msg').innerText = "اسم المستخدم لا يمكن أن تترك فارغة";
</script>
</body>
</html>
推荐答案
我尝试过时遇到过这个问题写土耳其字符。解决方案很简单。
I have already met with this issue when I tried to write Turkish characters. Solution is simple.
- 首先,将您的JavaScript代码移动到外部脚本文件。
-
其次,使用charset属性将您的脚本添加到HTML中,如下所示
- First, move your JavaScript code to external script file.
Second, add your script into HTML with charset attribute like below
<script src="external_script.js" charset="utf-8" type="text/javascript"></script>
这篇关于阿拉伯字符在JavaScript中无法正确显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文