把字符串转换为小写 - toLowerCase()

  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <h1>JavaScript 字符串方法</h1>
  6.  
  7. <p>把字符串转换为小写:</p>
  8.  
  9. <button onclick="myFunction()">试一试</button>
  10.  
  11. <p id="demo">Hello World!</p>
  12.  
  13. <script>
  14. function myFunction() {
  15. var text = document.getElementById("demo").innerHTML;
  16. document.getElementById("demo").innerHTML = text.toLowerCase();
  17. }
  18. </script>
  19.  
  20. </body>
  21. </html>