HTML中的id和name属性之间的区别 [英] Difference between id and name attributes in HTML

查看:100
本文介绍了HTML中的id和name属性之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

id 和 name 属性之间有什么区别?他们似乎都提供了提供标识符的相同目的。



我想知道(特别是关于HTML表单)是否需要或鼓励使用两者因为任何原因。

解决方案

在发送数据时使用名称属性在表单提交中。不同的控制反应不同。例如,您可能有几个单选按钮,它们具有不同的 id 属性,但同一个名称。提交时,响应中只有一个值 - 您选择的单选按钮。



当然,除此之外还有更多,但它肯定会让您想着正确的方向。


What is the difference between the id and name attributes? They both seem to serve the same purpose of providing an identifier.

I would like to know (specifically with regards to HTML forms) whether or not using both is necessary or encouraged for any reasons.

解决方案

The name attribute is used when sending data in a form submission. Different controls respond differently. For example, you may have several radio buttons with different id attributes, but the same name. When submitted, there is just the one value in the response - the radio button you selected.

Of course, there's more to it than that, but it will definitely get you thinking in the right direction.

这篇关于HTML中的id和name属性之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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