javascript实现字符串转大写的方法:1、通过“str.touppercase”方法将字符串转大写并返回;2、通过“str.tolocaleuppercase”方法将字符串根据本地化的大小写映射规则转化成的大写形式的新字符串。
本文操作环境:windows7系统、javascript1.8.5版,dell g3电脑。
javascript-将字符串转成大写的方法
str.touppercase()
str.touppercase() 方法将字符串转大写并返回
var str = "hello world hello world";var str2 = str.touppercase();console.log(str2);//hello world hello world
str.tolocaleuppercase()
str.tolocaleuppercase() 方法返回的是将字符串根据本地化的大小写映射规则转化成的大写形式的新字符串。
tolocaleuppercase() 不会影响输入的字符串本身的值;大多数情况下,这个方法与 touppercase() 会产生相同的值,但是对于一些语言(locale),例如土耳其语,因为它们的大小写映射规则与 unicode默认的映射规则不同,所以调用这两个方法将会产生不同的结果
var str = "hello world hello world";var str2 = str.tolocaleuppercase();console.log(str2);//hello world hello world
【推荐学习:js基础教程】
以上就是javascript怎么实现字符串转大写的详细内容。