HTML表单 - 是否需要名称和ID? [英] HTML Forms - Are name and id required?

查看:139
本文介绍了HTML表单 - 是否需要名称和ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我需要< input> 表单元素的名称 id 属性?



哪些用于POST数据发送,哪些可以排除?

解决方案

如果您打算处理该字段,则服务器端使用 name ,这是必需的 id 只有在标签元素被屏幕阅读器点击并访问时才能触发/调用窗体控件(

 < form method = POST action =form-processor.php> 
< input name = first_name value = john>
< / form>

结果

  $ _ POST = array('first_name'=>'john'); 

如果方法是 GET ,它会被追加到查询字符串:

http://site-name.com/form-handler.php?first_name=john

对于带有隐藏输入的查询字符串追加很流行:

< / p> input type =hiddenname =qvalue =1>


Why do I need the name and id attributes for <input> form elements?

Which is used for POST data sending and which can I exclude?

解决方案

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, selects ).

<form method=POST action="form-processor.php">
    <input name=first_name value=john>
</form>

results in

$_POST = array( 'first_name' => 'john' );

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:

<input type="hidden" name="q" value="1">

这篇关于HTML表单 - 是否需要名称和ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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