
|
网页的本质就是超级文本标记语言,通过结合使用其他的Web技术(如:脚本语言、公共网关接口、组件等),可以创造出功能强大的网页。因而,超级文本标记语言是万维网(Web)编程的基础,也就是说万维网是建立在超文本基础之上的。超级文本标记语言之所以称为超文本标记语言,是因为文本中包含了所谓“超级链接”点。 这篇文章给大家介绍的内容是关于html中<label>标签的for属性的详细分析,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。在freecodecamp上HTML教程的 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. 大概的意思是:最好的做法,是给 同时,给出一段示例代码,如下: <!-- Code 1 --> <label for="indoor"> <input id="indoor" type="radio" name="indoor-outdoor">Indoor </label>
代码中,label的for属性值与input的id属性值相同。从这段代码中,并不能看出关联在何处。 关于label的for属性的定义如下: The for attribute specifies which form element a label is bound to.译文:for属性指定label与表单中的哪个元素进行绑定。 示例代码: <!-- Code 2 --> <form action="/action_page.php"> <input type="radio" name="gender" id="male" value="male"> <label for="male">Male</label> <br> <input type="radio" name="gender" id="female" value="female"> <label for="female">Female</label> <br> <input type="radio" name="gender" id="other" value="other"> <label for="other">Other</label> <br> <input type="submit" value="Submit"> </form>
对比两段代码,不难发现,
如果,我们将两段代码中label的for属性删除,则之前的第1点和第2点不变,变化的是第3点。Code 1 的运营结果,点击label的内容,照旧能够选中单选按钮。而 Code 2 的则不同,点击label的内容,无法选中单选按钮。 经过简单的代码运行结果对比,我们能够验证文章开头引用的那段话是正确的。为label添加for属性的这个做法,能够提高代码质量。 相关文章推荐: 以上就是关于html中<label>标签的for属性的详细分析的详细内容,更多请关注php中文网其它相关文章! 网站建设是一个广义的术语,涵盖了许多不同的技能和学科中所使用的生产和维护的网站。 |
温馨提示:喜欢本站的话,请收藏一下本站!