如何将JavaScript中的字符串转换成全部大写形式?
- 内容介绍
- 文章标签
- 相关推荐
本文共计429个文字,预计阅读时间需要2分钟。
转换方法:
1.使用 `toUpperCase()` 函数,语法:`stringObject.toUpperCase()`
2.使用 `toLocaleUpperCase()` 函数,语法:`stringObject.toLocaleUpperCase()`
操作环境:
- Windows 7 系统- JavaScript 1.8.5 版本- Dell 计算机转换方法:1、使用toUpperCase()函数,语法“stringObject.toUpperCase()”;2、使用toLocaleUpperCase()函数,语法“stringObject.toLocaleUpperCase()”。
本教程操作环境:windows7系统、javascript1.8.5版、Dell G3电脑。
1、使用toUpperCase()函数将字符串转换为大写
toUpperCase() 方法用于把字符串转换为大写。
语法
stringObject.toUpperCase()
返回值
一个新的字符串,在其中 stringObject 的所有小写字符全部被转换为了大写字符。
实例
<script type="text/javascript"> var str="Hello World!" document.write(str.toUpperCase()) </script>
输出:
HELLO WORLD!
2、使用toLocaleUpperCase()函数将字符串转换为大写
toLocaleUpperCase() 方法用于把字符串转换为大写。
语法
stringObject.toLocaleUpperCase()
返回值
一个新的字符串,在其中 stringObject 的所有小写字符全部被转换为了大写字符。
说明
与 toUpperCase() 不同的是,toLocaleUpperCase() 方法按照本地方式把字符串转换为大写。只有几种语言(如土耳其语)具有地方特有的大小写映射,所有该方法的返回值通常与 toUpperCase() 一样。
实例
<script type="text/javascript"> var str="Hello World!" document.write(str.toLocaleUpperCase()) </script>
输出:
HELLO WORLD!
本文共计429个文字,预计阅读时间需要2分钟。
转换方法:
1.使用 `toUpperCase()` 函数,语法:`stringObject.toUpperCase()`
2.使用 `toLocaleUpperCase()` 函数,语法:`stringObject.toLocaleUpperCase()`
操作环境:
- Windows 7 系统- JavaScript 1.8.5 版本- Dell 计算机转换方法:1、使用toUpperCase()函数,语法“stringObject.toUpperCase()”;2、使用toLocaleUpperCase()函数,语法“stringObject.toLocaleUpperCase()”。
本教程操作环境:windows7系统、javascript1.8.5版、Dell G3电脑。
1、使用toUpperCase()函数将字符串转换为大写
toUpperCase() 方法用于把字符串转换为大写。
语法
stringObject.toUpperCase()
返回值
一个新的字符串,在其中 stringObject 的所有小写字符全部被转换为了大写字符。
实例
<script type="text/javascript"> var str="Hello World!" document.write(str.toUpperCase()) </script>
输出:
HELLO WORLD!
2、使用toLocaleUpperCase()函数将字符串转换为大写
toLocaleUpperCase() 方法用于把字符串转换为大写。
语法
stringObject.toLocaleUpperCase()
返回值
一个新的字符串,在其中 stringObject 的所有小写字符全部被转换为了大写字符。
说明
与 toUpperCase() 不同的是,toLocaleUpperCase() 方法按照本地方式把字符串转换为大写。只有几种语言(如土耳其语)具有地方特有的大小写映射,所有该方法的返回值通常与 toUpperCase() 一样。
实例
<script type="text/javascript"> var str="Hello World!" document.write(str.toLocaleUpperCase()) </script>
输出:
HELLO WORLD!

