問題描述
我有這個(gè)簡(jiǎn)單的功能:
Chrome、Firefox、IE:
Chrome, Firefox, IE:
Number(1000000).toLocaleString()
"1 000 000" // in french system, the space is the separator instead of the comma
Opera,傲游:
Number(1000000).toLocaleString()
"1000000"
為什么 Opera 和 Maxthon 不能格式化?他們支持這種方法,但沒有以正確的方式執(zhí)行?
why Opera and Maxthon cant format it? they support this method but dont execute it in the right way?
是否有任何 toLocaleString()
替換?
推薦答案
語(yǔ)言規(guī)范 定義非常開放:
生成一個(gè)字符串值,該值表示根據(jù)宿主環(huán)境當(dāng)前語(yǔ)言環(huán)境的約定格式化的數(shù)字值.此函數(shù)依賴于實(shí)現(xiàn),允許但不鼓勵(lì)它返回與 toString 相同的內(nèi)容.
15.7.4.3
Number.prototype.toLocaleString()
Produces a String value that represents this Number value formatted according to the conventions of the host environment’s current locale. This function is implementation-dependent, and it is permissible, but not encouraged, for it to return the same thing as toString.
允許不同的瀏覽器以不同的方式實(shí)現(xiàn)它,并且可以根據(jù)用戶選擇的語(yǔ)言環(huán)境以不同的方式實(shí)現(xiàn)它.
Different browsers are allowed to implement it differently, and can implement it differently based on the locale chosen by the user.
這篇關(guān)于并非所有瀏覽器都支持 toLocaleString()?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!