javascript怎么把字母转化为小写

JavaScript把字母转化为小写

方法1:使用toLowerCase() 方法

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

string.toLowerCase()

示例:

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

输出结果:

javascript怎么把字母转化为小写

方法2:使用toLocaleLowerCase() 方法

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

string.toLocaleLowerCase()

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

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

示例:

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

输出结果:

javascript怎么把字母转化为小写

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容