HTML DOM中的Style textTransform屬性用於設置或返回文本的大寫形式。它可用於使所需的文本大寫,小寫或將每個單詞的第一個字符大寫。
用法:
- 它返回textTransform屬性。
object.style.textTransform
- 它用於設置textTransform屬性。
object.style.textTransform = "capitalize|uppercase|lowercase| none|initial|inherit"
屬性值:
- capitalize:該值將文本中每個單詞的首字母大寫。
例:
<!DOCTYPE html> <html> <head> <title> DOM Style textTransform Property </title> </head> <body> <h1 style="color:green"> GeeksforGeeks </h1> <b>DOM Style textTransform Property</b> <p> The textTransform property can be used to capitalize, uppercase or lowercase the text. </p> <p class="content"> GeeksforGeeks is a computer science portal. </p> <button onclick="setTransform()"> Change textTransform </button> <!-- Script to capitalize first character of each word --> <script> function setTransform() { elem = document.querySelector('.content'); elem.style.textTransform = 'capitalize'; } </script> </body> </html>
輸出:
- 在單擊按鈕之前:
- 單擊按鈕後:
- 在單擊按鈕之前:
- uppercase:此值將文本的每個字母轉換為大寫。
例:
<!DOCTYPE html> <html> <head> <title> DOM Style textTransform Property </title> </head> <body> <h1 style="color:green"> GeeksforGeeks </h1> <b>DOM Style textTransform Property</b> <p> The textTransform property can be used to capitalize, uppercase or lowercase the text. </p> <p class="content"> GeeksforGeeks is a computer science portal. </p> <button onclick="setTransform()"> Change textTransform </button> <!-- Script to capitalize each character --> <script> function setTransform() { elem = document.querySelector('.content'); elem.style.textTransform = 'uppercase'; } </script> </body> </html>
輸出:
- 在單擊按鈕之前:
- 單擊按鈕後:
- 在單擊按鈕之前:
- lowercase:此值將文本的每個字母轉換為小寫。
例:
<!DOCTYPE html> <html> <head> <title> DOM Style textTransform Property </title> </head> <body> <h1 style="color:green"> GeeksforGeeks </h1> <b>DOM Style textTransform Property</b> <p> The textTransform property can be used to capitalize, uppercase or lowercase the text. </p> <p class="content"> GeeksforGeeks Is A ComPuTer sCiEnce PortAL. </p> <button onclick="setTransform()"> Change textTransform </button> <script> function setTransform() { elem = document.querySelector('.content'); elem.style.textTransform = 'lowercase'; } </script> </body> </html>
輸出:
- 在單擊按鈕之前:
- 單擊按鈕後:
- 在單擊按鈕之前:
- none:這是默認值,指定不進行任何轉換。
例:
<!DOCTYPE html> <html> <head> <title> DOM Style textTransform Property </title> <style> .content { width:500px; /* Set text-transform before to observe effect of 'none' */ text-transform:capitalize; } </style> </head> <body> <h1 style="color:green"> GeeksforGeeks </h1> <b>DOM Style textTransform Property</b> <p> The textTransform property can be used to capitalize, uppercase or lowercase the text. </p> <p class="content"> GeeksforGeeks is a computer science portal. </p> <button onclick="setTransform()"> Change textTransform </button> <!-- Script to convert lower case of each word --> <script> function setTransform() { elem = document.querySelector('.content'); elem.style.textTransform = 'none'; } </script> </body> </html>
輸出:
- 在單擊按鈕之前:
- 單擊按鈕後:
- 在單擊按鈕之前:
- initial:這用於將此屬性設置為其默認值。
例:
<!DOCTYPE html> <html> <head> <title> DOM Style textTransform Property </title> <style> .content { width:500px; /* Set text-transform before to observe effect of 'none' */ text-transform:capitalize; } </style> </head> <body> <h1 style="color:green"> GeeksforGeeks </h1> <b>DOM Style textTransform Property</b> <p> The textTransform property can be used to capitalize, uppercase or lowercase the text. </p>
支持的瀏覽器:下麵列出了DOM Style textTransform屬性支持的瀏覽器:
- 穀歌瀏覽器
- IE瀏覽器
- Firefox
- Opera
- 蘋果Safari
相關用法
- HTML Style right用法及代碼示例
- HTML Style top用法及代碼示例
- HTML Style animationTimingFunction用法及代碼示例
- HTML Style fontStyle用法及代碼示例
- HTML Style animationFillMode用法及代碼示例
- HTML Style lineHeight用法及代碼示例
- HTML Style textDecorationColor用法及代碼示例
- HTML Style pageBreakAfter用法及代碼示例
- HTML Style visibility用法及代碼示例
- HTML Style paddingLeft用法及代碼示例
- HTML Style paddingBottom用法及代碼示例
- HTML Style paddingTop用法及代碼示例
- HTML Style pageBreakInside用法及代碼示例
- HTML Style paddingRight用法及代碼示例
- HTML Style width用法及代碼示例
注:本文由純淨天空篩選整理自sayantanm19大神的英文原創作品 HTML | DOM Style textTransform Property。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。