Home >Web Front-end >Front-end Q&A >How to convert uppercase to lowercase in jquery

How to convert uppercase to lowercase in jquery

WBOY
WBOYOriginal
2022-04-02 15:26:152862browse

Method: 1. Use toLowerCase() method, the syntax is "Characters that need to be converted to lowercase.toLowerCase()"; 2. Use toLocaleLowerCase() method, the syntax is "Characters that need to be converted to lowercase.toLocaleLowerCase()" ".

How to convert uppercase to lowercase in jquery

The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.

How to convert uppercase to lowercase in jquery

1. The toLowerCase() method is used to convert a string to lowercase.

Syntax

string.toLowerCase()

The example is as follows:

<html>
<head>
<meta charset="utf-8">
<title>123</title>
</head>
<body>
<script>
var txt="ABCDEFGhijklmn";
document.write(txt.toLowerCase() + "<br>");
document.write(txt.toUpperCase());
</script>
</body>
</html>

Output result:

How to convert uppercase to lowercase in jquery

Expand knowledge:

The toUpperCase() method is used to convert a string to uppercase.

The syntax is:

string.toUpperCase()

2. toLocaleLowerCase() method

toLocaleLowerCase() method is based on the local host locale converts the string to lowercase.

Local is determined based on the browser's language settings.

Generally, this method returns the same result as the toLowerCase() method, only a few languages ​​(such as Turkish) have local-specific case mapping.

The syntax is:

string.toLocaleLowerCase()

The example is as follows:

<html>
<head>
<meta charset="utf-8">
<title>123</title>
</head>
<body>
<p>点击按钮将字符串转换为小写。</p>
<button onclick="myFunction()">点我</button>
<p id="demo"></p>
<script>
function myFunction() {
  var str = "ABCDEFGhijklmn";
  var res = str.toLocaleLowerCase();
  document.getElementById("demo").innerHTML = res;
}
</script>
</body>
</html>

Output result:

How to convert uppercase to lowercase in jquery

Expand knowledge:

The toLocaleUpperCase() method converts a string to uppercase according to the locale of the local host.

Recommended related video tutorials: jQuery video tutorial

The above is the detailed content of How to convert uppercase to lowercase in jquery. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn