1. name :指定標簽的名稱。
2. id :指定標簽的唯一標識。
3. html' target='_blank'>class :指定標簽的類名。
1. name
指定標簽的名稱。
1.1 格式input type= text name= username /
1.2 應用場景
①form表單:name可作為轉遞給服務器表單列表的變量名;如上面的傳到服務器的名稱為:username= text的值 。
②input type= radio 單選標簽:把幾個單選標簽的 name設為一個相同值時,將會進行單選操作。
input type= radio name= sex / 男 input type= radio name= sex / 女
③快速獲取一組name相同的標簽:獲取擁有相同name的標簽,一起進行操作,如:更改屬性、注冊事件等。
function changtxtcolor() { var txts = document.getElementsByName( txtcolor //獲取所有name=txtcolor 的標簽 for (var i = 0; i txts.length; i++) { //循環遍歷標簽,并把背景色改為red txts[i].style.backgroundColor = red }1.3 特性name屬性的值,在當前page頁面中并非唯一性。
2. id
指定標簽的唯一標識。
2.1 格式input type=password = userpwd /
①根據提供的唯一id號,快速獲取標簽對象。如:document.getElementById(id)
②用于充當label標簽for屬性的值:示例: label for= userid 用戶名: /label ,表示單擊此label標簽時,id為userid的標簽獲得焦點。
2.3 特性id屬性的值,在當前的page頁面要是唯一的。
3. class
指定標簽的類名。
3.1 格式input type=button class= btnsubmit /
①CSS操作,把一些特定樣式放到一個class類中,需要此樣式的標簽,可以在添加此類。
3.3 特性可以把多個類,放在一個class屬性里,但必須用空格隔開;如:
class btnsubmit btnopen
以上就是html中關于name和id以及class的區別介紹的詳細內容,html教程
鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。
新聞熱點
疑難解答