id 和 name 属性有什么区别?它们似乎都具有提供标识符的相同目的.
What is the difference between the id and name attributes? They both seem to serve the same purpose of providing an identifier.
我想知道(特别是关于 HTML 表单)是否有必要或出于任何原因鼓励使用两者.
I would like to know (specifically with regards to HTML forms) whether or not using both is necessary or encouraged for any reasons.
name 属性在表单提交中发送数据时使用.不同的控件响应不同.例如,您可能有几个具有不同 id 属性但 name 相同的单选按钮.提交后,响应中只有一个值 - 您选择的单选按钮.
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属性的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
Angular 2:在本地 .json 文件中找不到文件Angular 2: file not found on local .json file(Angular 2:在本地 .json 文件中找不到文件)
在 Ionic 2 中,如何创建使用 Ionic 组件的自定义指In Ionic 2, how do I create a custom directive that uses Ionic components?(在 Ionic 2 中,如何创建使用 Ionic 组件的自定义指令?)
如何在 ionic2 中的 pop() 之后重新加载离子页面How to reload the ion-page after pop() in ionic2(如何在 ionic2 中的 pop() 之后重新加载离子页面)
Javascript 将 URL 转换为 BASE64 图像Javascript Convert an URL to a BASE64 Image(Javascript 将 URL 转换为 BASE64 图像)
使用模式 Angular 2 进行输入验证Input validation with pattern Angular 2(使用模式 Angular 2 进行输入验证)
如何在角度2中动态更改css类名How to change the css class name dynamically in angular 2(如何在角度2中动态更改css类名)