什么是HTML标签中的For属性? [英] What is the For attribute for in an HTML tag?

查看:173
本文介绍了什么是HTML标签中的For属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < label id =label1for =txtTextBox> 

如果我将放在属性在那里?它允许你创建一个附加到DOM中的特定元素的标签。当标签收到鼠标向下的事件时,它会关注它附加的元素。

 < label for =username> ;用户名:其中/标签> 
< input type =textid =usernamename =username/>

当用户点击用户名:文本时,它将会关注文本框。



这对于可访问性也很好,因为屏幕阅读器在读取输入字段之前将读取标签的内部HTML,无论它们出现在DOM中的物理顺序如何。


  <label id="label1" for="txtTextBox">

what is the impact of label1 if I put the for attribute in there?

解决方案

It allows you to create a label that is attached to a specific element in the DOM. When the label receives a mouse down event it focuses the element it is attached to.

<label for="username">Username:</label>
<input type="text" id="username" name="username" />

When the user clicks on the "Username:" text it will focus the text box.

This is also good for accessibility as screen readers will read the label's inner HTML before reading the input field, regardless of the physical order they appear in the DOM.

这篇关于什么是HTML标签中的For属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆