当前位置:Gxlcms > JavaScript > JavaScript toUpperCase()方法使用详解

JavaScript toUpperCase()方法使用详解

时间:2021-07-01 10:21:17 帮助过:176人阅读

toUpperCase() 方法用于把字符串转换为大写。 

一个新的字符串,在其中 stringObject 的所有小写字符全部被转换为了大写字符。

语法为:stringObject.toUpperCase()
实例 

在本例中,"Hello world!" 将以大写字母来显示: 

  1. <script type="text/javascript">
  2. var str="Hello World!"
  3. document.write(str.toUpperCase())
  4. </script>

效果如下: 


相关方法举例如下: 

  1. <html>
  2. <body>
  3. <script type="text/javascript">
  4. var txt="Hello World!"
  5. document.write("<p>Big: " + txt.big() + "</p>")
  6. document.write("<p>Small: " + txt.small() + "</p>")
  7. document.write("<p>Bold: " + txt.bold() + "</p>")
  8. document.write("<p>Italic: " + txt.italics() + "</p>")
  9. document.write("<p>Blink: " + txt.blink() + " (does not work in IE)</p>")
  10. document.write("<p>Fixed: " + txt.fixed() + "</p>")
  11. document.write("<p>Strike: " + txt.strike() + "</p>")
  12. document.write("<p>Fontcolor: " + txt.fontcolor("Red") + "</p>")
  13. document.write("<p>Fontsize: " + txt.fontsize(16) + "</p>")
  14. document.write("<p>Lowercase: " + txt.toLowerCase() + "</p>")
  15. document.write("<p>Uppercase: " + txt.toUpperCase() + "</p>")
  16. document.write("<p>Subscript: " + txt.sub() + "</p>")
  17. document.write("<p>Superscript: " + txt.sup() + "</p>")
  18. document.write("<p>Link: " + txt.link(//www.gxlcms.com) + "</p>")
  19. </script>
  20. </body>
  21. </html>

效果如下:

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

人气教程排行