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))


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部