關於html name 和id,Form input without an associated label or title attribute

來源:互聯網
上載者:User

標籤:重複   關係   替代   控制項   屬性   required   input   欄位   mod   

這不是一個錯誤,它建議將標籤與UX方便起見相應的表單元素。例如為名稱欄位:

然後給出一個樣本

<label for="name">Nazwa:</label><textarea class="form-control" id="name" name="newTodo" data-ng-model="formData.newTodo" required></textarea>

讓label的for指向input的id,這樣click這個label時,input會獲得焦點。

 

那name和id的關係呢

ID就像是一個人的社會安全號碼碼,而Name就像是他的名字,ID顯然是唯一的,而Name是可以重複的。

以下只能用name:

1. 表單(form)的控制項名,提交的資料都用控制項的name而不是id來控制。

因為有許多name會同時對應多個控制項,比如 checkbox和radio,而id必須是全文檔中唯一的。此外瀏覽器會根據name來設定發送到伺服器的request。因此如果用id,伺服器是無 法得到資料的。

2. frame和window的名字,用於在其他frame或window指定target。

 

以下只能用id:

1. label與form控制項的關聯, My Input for屬性指定與label關聯的元素的id,不可用name替代。

2. CSS的元素選擇機制,

關於html name 和id,Form input without an associated label or title attribute

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.