HTML 表单 - 是否需要名称和 ID? [英] HTML Forms - Are name and id required?
本文介绍了HTML 表单 - 是否需要名称和 ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么我需要 表单元素的 name 和 id 属性?
Why do I need the name and id attributes for <input>
form elements?
哪些用于POST数据发送,哪些可以排除?
Which is used for POST data sending and which can I exclude?
推荐答案
name
由服务器端使用.如果您计划处理该字段,这是必要的.id
只是这样 label
元素,当屏幕阅读器点击和访问时,可以触发/调用表单控件(输入和选择).
name
is used by the server-side. This is necessary if you plan to process the field. id
is only so label
elements, when clicked and accessed by screen-readers, can trigger/invoke the form controls (inputs and selects).
<form method=POST action="form-processor.php">
<input name=first_name value=john>
</form>
结果
$_POST = array('first_name' => 'john');
如果方法是GET
,则附加到查询字符串中:
If the method is GET
, it's appended to the query string:
http://site-name.com/form-handler.php?first_name=john
附加隐藏输入的查询字符串很流行:
It's popular for query string appending with hidden inputs:
这篇关于HTML 表单 - 是否需要名称和 ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文