在html页面中将英语数字转换为阿拉伯数字 [英] Convert from English Digits to Arabic ones in html page
本文介绍了在html页面中将英语数字转换为阿拉伯数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要将给定HTML页面中显示的所有英文数字转换为阿拉伯数字(以独立于用户浏览器编码).我更喜欢使用javascript,如果可以使用CSS来处理,那会很棒.
I need to convert all English numbers that appear in a given HTML page to Arabic ones (to be independent from the user browser encoding). I prefer to use javascript or it will be great if this can be handled using CSS.
我找到了一些执行此操作的页面,但是我发现在源代码中以阿拉伯字母和ASCII表示形式添加了阿拉伯字母.这是否意味着他们正在应用某种Java脚本功能?
I found some pages doing this but I found that the Arabic letters are added with their ASCII representation in the source code. Does it mean that they are applying some sort of a java script function?
任何提示我该怎么做?
推荐答案
直接替换函数如何?
String.prototype.toIndiaDigits= function(){
var id= ['۰','۱','۲','۳','۴','۵','۶','۷','۸','۹'];
return this.replace(/[0-9]/g, function(w){
return id[+w]
});
}
// test
var S='The year 2009 has only 365 days';
alert(S.toIndiaDigits());
/* returned value: (String)
The year ۲۰۰۹ has only ۳۶۵ days
*/
这篇关于在html页面中将英语数字转换为阿拉伯数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文