javascript怎么把字母转化为小写

2021-10-13,,

javascript把字母转化为小写的方法:1、使用toLowerCase(),语法“string.toLowerCase()”;2、使用toLocaleLowerCase(),语法“string.toLocaleLowerCase()”。

/2021/10/feb897d4.jpg

本教程操作环境:windows7系统、javascript1.8.5版、Dell G3电脑。

javascript把字母转化为小写

方法1:使用toLowerCase() 方法

toLowerCase() 方法用于把字符串转换为小写。具体语法格式如下:

string.toLowerCase()

示例:

<script type="text/javascript">
console.log("A".toLowerCase());
console.log("B".toLowerCase());
console.log("C".toLowerCase());
</script>

输出结果:

/2021/10/7e3e82fd.png" /2021/10/7e3e82fd.png" alt="1.png

方法2:使用toLocaleLowerCase() 方法

toLocaleLowerCase() 方法根据本地主机的语言环境把字符串转换为小写。具体语法格式如下:

string.toLocaleLowerCase()

通常,该方法与 toLowerCase() 方法返回的结果相同,只有几种语言(如土耳其语)具有地方特有的大小写映射。

注意: toLocaleLowerCase() 方法没有改变原始字符串。

示例:

<script type="text/javascript">
document.write("P".toLocaleLowerCase());
document.write("H".toLocaleLowerCase());
document.write("P".toLocaleLowerCase());
</script>

输出结果:

/2021/10/f81e4fb2.png" /2021/10/f81e4fb2.png" alt="3.png

【推荐学习:javascript高级教程】

以上就是javascript怎么把字母转化为小写的详细内容,更多请关注北冥有鱼其它相关文章!

本文转载自【PHP中文网】,希望能给您带来帮助,苟日新、日日新、又日新,生命不息,学习不止。

《javascript怎么把字母转化为小写.doc》

下载本文的Word格式文档,以方便收藏与打印。