html名称属性的目的是什么? [英] What is the purpose of the html name attribute?

查看:91
本文介绍了html名称属性的目的是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

输入名称属性的目的是什么? span ,或 div 标签?是否应该使用 id 标签?

What is the purpose of the name attribute on input, span, or div tags? Should an id tag be used instead?

来自 Mozilla的文档

<label for="User">Click me</label>
<input type="text" id="User" name="Name" />


推荐答案

名称 GET 或<$ $ c> POST 表格。

具体到示例,如果你有:

Specific to the example if you had:

<form action="http://localhost" method="POST">
    <label for="User">Click me</label>
    <input type="text" id="User" name="Name" value="foo" />
    <input type="submit" value="submit" />
</form>

并且您提交表单,服务器 localhost 将收到如下内容正文:

and you submit the form, the server localhost will receive a content body like:

Name=foo

正如另一篇文章提到的那样,通常用像PHP这样的服务器端语言解析成更易于使用的东西。

which as another post mentions, is usually parsed by a server side language like PHP into something easier to work with.

id 属性标识 DOM 的输入。如果您指定的输入没有 name 但是 id 并尝试通过提交GET POST 服务器无法正确解析它。

The id attribute identifies the input to the DOM. If you specify an input with no name but an id and try to submit it via a GET or POST it will not be parsed correctly by the server.

这篇关于html名称属性的目的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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