關於html中標籤的for屬性的詳細分析
這篇文章給大家介紹的內容是關於html中
在freecodecamp上HTML教程的Create a Set of Radio Buttons
這一節中,看到這樣一段話,
It is considered best practice to set a for attribute on the label element, with a value that matches the value of the id attribute of the input element. This allows assistive technologies to create a linked relationship between the label and the child input element.##ween the label and the child input element.##ween the label and the child input element.## :最好的做法,是給
label標籤,加上for
屬性,其值與input
標籤的id
屬性的值相同,以在label和input之間建立關聯。 同時,給出一段範例程式碼,如下:
<!-- Code 1 --> <label> <input>Indoor </label>
#程式碼中,label的for屬性值與input的id屬性值相同。從這段程式碼中,並不能看出關聯在何處。
關於label的for屬性的定義如下:
The for attribute specifies which form element a label is bound to.譯文:for屬性指定label與表單中的哪個元素進行綁定。
範例程式碼:<!-- Code 2 -->
比較兩段程式碼,不難發現,
- label與input在頁面上的排列方式不同。透過Chrome的開發者工具不難發現,Code 1 的運行結果,label標籤將input標籤遮蓋,Code 2 的運行結果,label標籤與input標籤並列。
- label與input一一對應。點選label的內容,對應的單端按鈕都會被選取。
- 如果,我們將兩段程式碼中label的for屬性刪除,則先前的第1點和第2點不變,變化的是第3點。 Code 1 的營運結果,點選label的內容,照舊能夠選取單選按鈕。而 Code 2 的則不同,點選label的內容,無法選取單選按鈕。
html中標籤嵌套的問題如何解決
以上是關於html中標籤的for屬性的詳細分析的詳細內容。更多資訊請關注PHP中文網其他相關文章!

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)
