Difference between toLocaleLowerCase() and toLowerCase()
我想tolowercase小提琴与tolocalelowercase()和()的方法。P></
1 2 3 4 5 6 7 | function ByLocale() { document.getElementById("demo").innerText.toLocaleLowerCase(); } function ByLower() { document.getElementById("demo").innerText.toLowerCase(); } |
1 2 3 4 5 6 7 8 9 | <p> Click the button to convert the string"HELLO World!" to lowercase letters. </p> <button onclick="ByLocale();">By Locale LowerCase</button> <button onclick="ByLower();">By LowerCase</button> <p id="demo">HELLO World! </p> |
P></
我的问题是:P></
- 因为都是什么地方,茶似乎相似函数返回的输出?
- 二是差分方法is the between these?
- 为什么不让executed code is the小提琴?
与
查看MDN上的描述:
The toLocaleLowerCase() method returns the value of the string converted to lower case according to any locale-specific case mappings. toLocaleLowerCase() does not affect the value of the string itself. In most cases, this will produce the same result as toLowerCase(), but for some locales, such as Turkish, whose case mappings do not follow the default case mappings in Unicode, there may be a different result.
为完整起见,除上套管外,
现在,关于你的代码片段没有做任何事情的问题。实际上有两个问题。
这些方法返回新字符串,不修改原始字符串(javascript字符串是不可变的)。您需要将值重新分配回元素。
工作代码段:
1 2 3 4 5 6 7 8 9 | function ByLocale() { var el = document.getElementById("demo"); el.textContent = el.textContent.toLocaleLowerCase(); } function ByLower() { var el = document.getElementById("demo"); el.textContent = el.textContent.toLowerCase(); } |
1 2 3 4 5 6 7 8 9 | <p> Click the button to convert the string"HELLO World!" to lowercase letters. </p> <button onclick="ByLocale();">By Locale LowerCase</button> <button onclick="ByLower();">By LowerCase</button> <p id="demo">HELLO World! </p> |