UTF-8被定義為HTML5的預設字元編碼,用於完美顯示HTML頁面。它鼓勵 Web 開發人員使用 UTF-8,因為它涵蓋了使用一個位元組的實體中的所有字元和符號,並且在所有瀏覽器中都能正常運作。 Unicode 轉換格式 – 8 位元是將鍵入的字元轉換為機器可讀代碼的方法。 charset 屬性用於對 HTML 進行字元編碼。
HTML 中的 UTF-8 語法
中 UTF-8 字元編碼規範標籤給出為:
<meta charset="UTF-8">
這裡元提供有關 HTML 文件的數據,但它是機器可讀的。它們的元素指定關鍵字、最後修改時間等。此元標記包含字元集,它在存取頁面時告訴網頁瀏覽器。
編碼是指將給定的數字轉換為機器可以理解的二進制數字的方式。這裡每個字元分別由一個或多個位元組組成。
作為範例,讓我們以文字嗨,EDUCBA!
UTF-8 字元編碼如下:
01001000 01101001 00101100 01100101 01000100 01010101 01000011 01000010 0100101 01000011 01000010 010000001 101000
轉換為機器可讀的二進位結構。使用 UTF-8 的關鍵重要性
HTML 中的 UTF-8 範例
範例#1
代碼:
new.html
<meta charset="UTF-8">Page Title !مرحبا بالعالم
你叫什么名字?
This is Chinese Language.
This is the code demonstrating encoding Process
說明:
輸出:
範例#2
代碼:
lang.html
<!DOCTYPE HTML > <html> <head> <title>HTML sample -buttons</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </head> <body> <form action="addressing" method="post"> <fieldset> <legend>Selection list</legend> Checkbox: <input type="checkbox" name="King" value="one"><br> RadioButton1: <input type="radio" name="Queen" value="two"><br> RadioButton2: <input type="radio" name="Jack" value="three" checked="checked"><br> </fieldset> <fieldset> <legend>Give Input</legend> Login Id: <input type="text" name="Login name"><br> Password: <input type="password" name="Strong Password"><br> </fieldset> <fieldset> <legend>Designation</legend> <p><input type="checkbox" name=" Software Engineer"> Software Engineer</p> <p><input type="checkbox" name="Data Analyst"> Data Analyst</p> <p><input type="checkbox" name="Web Developer"> Web Developer</p> <p><input type="checkbox" name=" Senior Analyst"> Senior Analyst</p> </fieldset> <p><input type="submit" value="press"> <input type="reset"></p> </form> </body> </html>
說明:
輸出:
範例 #3
代碼:
mett.html
<!DOCTYPE html> <html> <head> <title> HTML UTF-8 Charset </title> <meta name="keywords" charset="UTF-8" content="Meta Tags, Metadata" /> </head> <body style="text-align:left"> <H1>Hi Instructor!</H1> <h2> This is my formal e-mail for the joining. </h2> <h3>Hola, me llamo Juan </h3> <b>Mucho gusto </b> </body> </html>
說明:
輸出:
Using JavaScript.
Code:
name.js
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>UTF-8 Charset</title> <style> span { color: blue; } span.name { color: red; font-weight: bolder; } </style> <script src="https://code.jquery.com/jquery-3.5.0.js"></script> </head> <body> <div> <span>Thomas,</span> <span>John Betson,</span> <span>Valli Tromson</span> </div> <div> <span>आभरणा,</span> <span>आचुथान,</span> <span>अभिनंध</span> </div> <script> $( "div span:first-child" ) .css( "text-decoration", "Underline" ) .hover(function() { $( this ).addClass( "name" ); }); </script> </body> </html>
Explanation:
Output:
So that’s all about the encoding of UTF-8 in HTML. We have gone through Unicode and encodes in the HTML briefly and the implementation of HTML and JavaScript. In this emerging software world, the character sets are not made so feasible; therefore, there comes character encoding schemes to be done with the HTML and other programming languages. Therefore, it is said that it is best to use UTF-8 everywhere where it doesn’t need any conversions encoding.
以上是HTML 中的 UTF-8的詳細內容。更多資訊請關注PHP中文網其他相關文章!