Created
September 27, 2020 05:56
-
-
Save mhdzli/c86afd115d0cd1a5ea3d7557579617f6 to your computer and use it in GitHub Desktop.
persian number with javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
$(document).ready(function () { | |
ConvertNumberToPersion(); | |
}); | |
function ConvertNumberToPersion() { | |
persian = { 0: '۰', 1: '۱', 2: '۲', 3: '۳', 4: '۴', 5: '۵', 6: '۶', 7: '۷', 8: '۸', 9: '۹' }; | |
function traverse(el) { | |
if (el.nodeType == 3) { | |
var list = el.data.match(/[0-9]/g); | |
if (list != null && list.length != 0) { | |
for (var i = 0; i < list.length; i++) | |
el.data = el.data.replace(list[i], persian[list[i]]); | |
} | |
} | |
for (var i = 0; i < el.childNodes.length; i++) { | |
traverse(el.childNodes[i]); | |
} | |
} | |
traverse(document.body); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment