html强制转换为数字,在html页面中将英文数字转换为阿拉伯数字

P9Q..

5

将英语(拉丁)数字转换为波斯数字和阿拉伯数字。

//English to Persian digits.

String.prototype.toFa= function() {

return this.replace(/\d/g, d => '??????????'[d])

}

//English to Arabic digits.

String.prototype.toAr= function() {

return this.replace(/\d/g, d => '??????????'[d])

}

//English to either Persian or Arabic digits.

String.prototype.toIn= function(e) {

return this.replace(/\d/g, d => e ? '??????????'[d] : '??????????'[d])

}

//English to Persian digits using unicode.

String.prototype.toFaUni= function() {

return this.replace(/\d/g, d => String.fromCharCode('0x06F'+d))

}

//English to Arabic digits using unicode.

String.prototype.toArUni= function() {

return this.replace(/\d/g, d => String.fromCharCode('0x066'+d))

}

//English to either Persian or Arabic digits.

String.prototype.toInUni= function(e) {

return this.replace(/\d/g, d => String.fromCharCode('0x06'+(e ? '6':'F')+d))

}

//examples

let text = 'It is 30/08/2018 at 8:24 AM'

//using array

alert(text.toFa())

alert(text.toAr())

alert(text.toIn(0))

alert(text.toIn(1))

//using unicode

alert(text.toFaUni())

alert(text.toArUni())

alert(text.toInUni(0))

alert(text.toInUni(1))

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值