How can I view Arabic/Persian numbers in a HTML page with strict doctype?

后端 未结 10 1850
时光说笑
时光说笑 2020-12-18 19:26

I have an HTML page that is right-to-left. When I don\'t use any doctype, my numbers are in Arabic/Persian, but when I use strict mode they turn to English.

         


        
相关标签:
10条回答
  • 2020-12-18 20:05

    If you use persian fonts like 'BNazanin' and write :

    http-equiv="Content-Type" content="text/html; charset=UTF-8"
    and http-equiv="Content-Language" content="fa" in meta tags.

    You can then see the numbers in persian.

    and if you use lang='En' in some tags in your html page the numbers in that tag will be displayed in english.

    0 讨论(0)
  • 2020-12-18 20:06

    It is very simple to view Arabic/Persian numbers in a HTML page.

    I solved the same problem by changing the font name,

    In my case I want to display the same character to all users

    you can choose a font that contains Arabic-Hndi digits and import it using the css ( @font-face ) then simply use it,

    This works fine for all major browsers (IE .. Firefox .. Chrome)

    look at this result

    here is the full code of the page:

    <html>
    <head>
    
    </head>
    <body>
    <style type="text/css">
    
    @font-face {
        font-family: ArabicTwo_Bold;
        src: url( ArabicTwo_Bold.eot);
    }
    
    @font-face {
        font-family: ArabicTwo_Bold;
        src: url( ArabicTwo_Bold.ttf);
    }
    
    
    div , input {
     font-family: ArabicTwo_Bold;
    }
    </style>
    
    
    <input type='text' value='هذا نص هندي 123456 ' />
    <div> هذا نص هندي 123456  </div>
    </body>
    </html>
    
    0 讨论(0)
  • 2020-12-18 20:06

    In case you need to replace some English to Arabic numerals and not the whole HTML, pass the number you need to this function.

    function toArabicNumeral(en) {
        return ("" + en).replace(/[0-9]/g, function(t) {
            return "٠١٢٣٤٥٦٧٨٩".substr(+t, 1);
        });
    }
    
    0 讨论(0)
  • 2020-12-18 20:09

    You can convert English digits to Persian digits using this JavaScript code in your template:

        <script type="text/javascript">
        var replaceDigits = function() {
            var map = ["&\#1776;","&\#1777;","&\#1778;","&\#1779;","&\#1780;","&\#1781;","&\#1782;","&\#1783;","&\#1784;","&\#1785;"]
            document.body.innerHTML = document.body.innerHTML.replace(/\d(?=[^<>]*(<|$))/g, function($0) { return map[$0]});
        }
        window.onload = replaceDigits;
        </script>
    
    0 讨论(0)
提交回复
热议问题