什么时候应该使用HTML4 / HTML5中的name属性? [英] When should I use the name attribute in HTML4/HTML5?

查看:341
本文介绍了什么时候应该使用HTML4 / HTML5中的name属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过阅读W3C关于HTML4.01和HTML5的文档,我知道name属性最初作为< a> 标签的属性存在,以允许人们链接到文档中的锚点。然而,现在所有主要的浏览器厂商都允许通过id属性链接到文档中的任何html元素,但名称仍然有任何实际用途,属性?如果是这样,我应该如何使用名称属性?解析方案

有一件事想到的是单选按钮:你必须使用 name 来指定哪些是同一组的组成部分。

 <形式> 
< input type =radioname =sexvalue =male/>男性< br />
< input type =radioname =sexvalue =female/>女
< / form>


I know by reading the W3C documention for HTML4.01 and HTML5 that the "name" attribute originally existed as a property of the <a> tag to permit people to link to an anchor point within a document.

However, now that all major browser venders allow linking to any html element within a document via the "id" attribute, is there still any real use for the "name" attribute? If so, how should I be using the "name" attribute?

解决方案

One thing that comes to mind are radio buttons: you have to use name to specify which ones are part of the same group.

<form>
<input type="radio" name="sex" value="male" /> Male<br />
<input type="radio" name="sex" value="female" /> Female
</form> 

这篇关于什么时候应该使用HTML4 / HTML5中的name属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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