HTML中的id和name属性之间的区别 [英] Difference between id and name attributes in HTML
问题描述
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屋!