在 html 页面中从英文数字转换为阿拉伯数字 [英] Convert from English Digits to Arabic ones in html page

查看:51
本文介绍了在 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?

知道我该怎么做这样的事情吗?

Any clue how can I do something like this?

推荐答案

直接替换功能怎么样?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆