Mah*_*hdi 12 html doctype numbers xhtml-1.0-strict arabic
我有一个从右到左的HTML页面.当我不使用任何doctype时,我的数字是阿拉伯语/波斯语,但是当我使用严格模式时,他们会转向英语.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Final//EN">
Run Code Online (Sandbox Code Playgroud)
在添加doctype之前:

添加doctype后:

我也将这些元标记添加到我的页面:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Language" content="fa" />
Run Code Online (Sandbox Code Playgroud)
那么如何在具有严格doctype的页面中查看阿拉伯数字(在IE中,因为Firefox无论如何都不显示阿拉伯数字)?
这是一个小的javascript代码,将1234字符串转换为1234字符串
var map =
[
"&\#1632;","&\#1633;","&\#1634;","&\#1635;","&\#1636;",
"&\#1637;","&\#1638;","&\#1639;","&\#1640;","&\#1641;"
];
function getArabicNumbers(str)
{
var newStr = "";
str = String(str);
for(i=0; i<str.length; i++)
{
newStr += map[parseInt(str.charAt(i))];
}
return newStr;
}
Run Code Online (Sandbox Code Playgroud)
您可以使用模板中的此 JavaScript 代码将英文数字转换为波斯数字:
<script type="text/javascript">
var replaceDigits = function() {
var map = ["&\#1776;","&\#1777;","&\#1778;","&\#1779;","&\#1780;","&\#1781;","&\#1782;","&\#1783;","&\#1784;","&\#1785;"]
document.body.innerHTML = document.body.innerHTML.replace(/\d(?=[^<>]*(<|$))/g, function($0) { return map[$0]});
}
window.onload = replaceDigits;
</script>
Run Code Online (Sandbox Code Playgroud)
如果您需要将一些英文替换为阿拉伯数字而不是整个 HTML,请将您需要的数字传递给此函数。
\nfunction toArabicNumeral(en) {\n return ("" + en).replace(/[0-9]/g, function(t) {\n return "\xd9\xa0\xd9\xa1\xd9\xa2\xd9\xa3\xd9\xa4\xd9\xa5\xd9\xa6\xd9\xa7\xd9\xa8\xd9\xa9".slice(+t, +t+1);\n });\n}\nRun Code Online (Sandbox Code Playgroud)\n
无论文本方向如何(在 Chrome、Safari、Firefox 和 Opera 中),这对我都有效:
\n\n<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Final//EN">\n\n<html>\n <head>\n <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">\n <style type="text/css">\n body { direction: rtl; }\n </style>\n </head>\n\n <body>\n \xdb\xb4\xdb\xb2\n </body>\n</html>\nRun Code Online (Sandbox Code Playgroud)\n\n(省略了content-language因为这里不需要\xe2\x80\x99。)