HTML 中按钮作为form表单元素提交特性两则 --- 参HTML考标准分析
相同name的submit 类型的input提交行为
描述
这种情况,
<input type="submit" name="ACTION" value="Apply"/>
<input type="submit" name="ACTION" value="Cancel"/>
其能够作为提交内容, 发送到服务器段的参数的按钮, 对应被点击激活的按钮。
这表示多个 同名的name, 一次提交只能激活一个。
例如点击了 apply, ACTION=Apply会被传送到服务器端。 这样服务器端就可以判断对于同样提交的一份数据,
需要执行什么样的操作, 是修改, 还是删除?
Code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>phpStudy 探针 2014 </title>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<form method="post">
<textarea>
<?php
echo "IF_ACTION=" . $_POST['IF_ACTION'];
echo "data=" . $_POST['data'];
?>
</textarea>
<input type="text" name="data" value="data"/>
<input type="submit" name="IF_ACTION" value="Apply"/>
<input type="submit" name="IF_ACTION" value="Cancel"/>
</form>
</body>
</html>
标准解读
https://www.w3.org/TR/html4/interact/forms.html#current-value
见下面段落中(关于form表单中 successful control的定义),这一句:
If a form contains more than one submit button, only the activated submit button is successful.
所有的 提交按钮中, 只能被激活的那个按钮, 是successful的, 即可以提交到服务器端。
段落:
17.13.2 Successful controls
A successful control is "valid" for submission. Every successful control has its control name paired with its current value as part of the submitted form data set. A successful control must be defined within a FORM element and must have a control name.
However:
- Controls that are disabled cannot be successful.
- If a form contains more than one submit button, only the activated submit button is successful.
- All "on" checkboxes may be successful.
- For radio buttons that share the same value of the name attribute, only the "on" radio button may be successful.
- For menus, the control name is provided by a SELECT element and values are provided by OPTION elements. Only selected options may be successful. When no options are selected, the control is not successful and neither the name nor any values are submitted to the server when the form is submitted.
- The current value of a file select is a list of one or more file names. Upon submission of the form, the contents of each file are submitted with the rest of the form data. The file contents are packaged according to the form's content type.
- The current value of an object control is determined by the object's implementation.
类型为 button 的 input为什么不能提交 ?
描述
如果有一个button类型的按钮存在与form中, 则form被提交, 其提交的参数中, 不会存在 这个按钮的 name 和 value。
如下代码: pushbutton 在请求的数据中不存在。
<form id="fileupload" name="fileupload" method="post" action="/index.php">
<input type="file" name="testfile" multiple="multiple"></br>
<input type="text" name="textinput" value="textinputvalue"></br>
<input type="button" name="pushbutton" value="pushbutton">
<input type="submit" name="submit" value="upload"></br>
</form>
Code
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="./jquery.js"></script>
<link rel="stylesheet" href="./test.css" />
</head>
<body>
<style>
</style>
<form id="fileupload" name="fileupload" method="post" action="/index.php">
<input type="file" name="testfile" multiple="multiple"></br>
<input type="text" name="textinput" value="textinputvalue"></br>
<input type="button" name="pushbutton" value="pushbutton">
<input type="submit" name="submit" value="upload"></br>
</form>
<script>
document.write("enctype="+document.getElementById("fileupload").getAttribute("enctype").toLowerCase());
</script>
</body>
</html>
标准分析
https://www.w3.org/TR/html401/interact/forms.html#buttons
标准对button的解释, 很清楚了, 包括三种类型:
1、 提交类型 ( 用于提交表单数据, 用户点击提交按钮 , 或者光标表单内点击键盘的enter键盘 -- IE实现是第一个submit按钮提交被触发 )
2、 重置类型( reset button - 不用与后台交互, 就可以将页面控件的默认值, 现实出来, 即HTML value attribute的值。 )
3、 推送类型(push button - 不执提交和重置, 需要绑定js处理事件, 例如将表单参数校验成功后再提交form)
鉴于它的类型作用, 其确实没有必要提交, reset按钮也类似。
buttons Authors may create three types of buttons:
- submit buttons: When activated, a submit button submits a form. A form may contain more than one submit button.
- reset buttons: When activated, a reset button resets all controls to their initial values.
- push buttons: Push buttons have no default behavior. Each push button may have client-side scripts associated with the element's event attributes. When an event occurs (e.g., the user presses the button, releases it, etc.), the associated script is triggered.
Authors should specify the scripting language of a push button script through a default script declaration (with the META element).
Authors create buttons with the BUTTON element or the INPUT element. Please consult the definitions of these elements for details about specifying different button types.
Note. Authors should note that the BUTTON element offers richer rendering capabilities than the INPUT element.
HTML 中按钮作为form表单元素提交特性两则 --- 参HTML考标准分析的更多相关文章
- Form表单元素
Form表单元素 action method input: name value type: text password button radio checkbox file submit reset ...
- jQuery操作Form表单元素
Web开发中常常须要操作表单,form表单元素有select.checkbox.radio.textarea.button.file.text.hidden.password等. 当中checkbox ...
- 【jQuery】form表单元素序列化为json对象
序列化form表单元素为json对象: <!Doctype html> <html xmlns=http://www.w3.org/1999/xhtml> <head&g ...
- form表单 无法提交js动态添加的表单元素问题。。
第一种情况, 这种情况js动态添加的表单元素是不能提交到服务器端的 <table> <form method="post" action=" url ...
- form表单元素的值序列化成对象
/** * 将form表单元素的值序列化成对象 * param: form jquery form对象 */ var serializeObject = function(form) { var o ...
- 将form表单元素的值序列化成对象
/**jQuery * 将form表单元素的值序列化成对象 * @returns object */ var serializeObject = function(form) { var o = {} ...
- form表单元素设置只读
form表单元素设置只读 CreateTime--2017年5月5日11:42:41 Author:Marydon 1.设置文本框只读 <!-- 方法一:简写 --> <inpu ...
- form表单的提交方式
开发中表单提交是很常见的,表单的提交方式也多种方式. 1.使用submit按钮提交表单 <input type="submit"/> <!DOCTYPE htm ...
- 使用ajax方法实现form表单的提交(附源码)
写在前面的话 在使用form表单的时候,一旦点击提交触发submit事件,一般会使得页面跳转,页面间的跳转等行为的控制权往往在后端,后端会控制页面的跳转及数据传递,但是在某些时候不希望页面跳转,或者说 ...
随机推荐
- topcoder SRM 610 DIV2 DivideByZero
题目的意思是给你一组数,然后不断的进行除法(注意是大数除以小数),然后将得到的结果加入这组数种然后继续进行除法, 直到没有新添加的数为止 此题按照提议模拟即可 注意要保持元素的不同 int Count ...
- thinkphp常用Config.php配置项
<?php return array( //'配置项'=>'配置值' 'DB_HOST' => 'localhost', 'DB_USER' => 'root', 'DB_PW ...
- SQL 中怎么查询一个数据库中一共有多少个表
用户表:select count(*) 总表数 from sysobjects where xtype='u' 总表数:select count(*) 总表数 from sysobject s whe ...
- [LintCode] Longest Consecutive Sequence 求最长连续序列
Given an unsorted array of integers, find the length of the longest consecutive elements sequence. H ...
- 禁止浏览器直接访问php文件
框架中很多php文件并不是用来如果熟悉框架的路径就能直接访问这个文件,虽然访问到了也不能看到什么(他看到的是编译过后的html文件),但还是觉的很不安全. 可以通过下面这种方法拒绝他人的从浏览器中的访 ...
- error CS0016: 未能写入输出文件
win7 下解决办法: 1.打开C:\Windows ,找到 TEMP 文件夹 2. 进行权限设置,点击编辑,找到 IIS-User,勾选所有权限
- PHP filesystem attack vectors
http://www.ush.it/2009/02/08/php-filesystem-attack-vectors/ On Apr 07, 2008 I spoke with Kuza55 and ...
- 安装配置redis
1.1查看当前系统环境 查看当前系统版本信息: 查看当前网络连通情况: 1.2使用yum安装 1.3确认redis的安装目录 1.4查看\修改配置文件 1.5启动redis服务并验证 1.6使用tel ...
- jquery暂停和中断循环
jquery对数组进行循环,如果要求每次循环的时候暂停2秒钟,在.earch循环的时候,无论怎么设置,都不会暂停. setTimeout也只是在第一次执行的时候暂停. 原因猜测: js开始执行多线程? ...
- WordPress插件开发实例教程 - 版权插件
说明:本教程仅限学习,高手请绕道 开发程序:WordPress 3.9-RC1 使用主题:Twenty Fourteen 在开始之前,需要注意三件事情 I.给插件取一个个性化的名字,越个性化越好,以防 ...