把字符串转换为大写 - toUpperCase()
- <!DOCTYPE html>
- <html>
- <body>
- <h1>JavaScript 字符串方法</h1>
- <p>把字符串转换为大写:</p>
- <button onclick="myFunction()">试一试</button>
- <p id="demo">Hello World!</p>
- <script>
- function myFunction() {
- var text = document.getElementById("demo").innerHTML;
- document.getElementById("demo").innerHTML = text.toUpperCase();
- }
- </script>
- </body>
- </html>