http://msdn.microsoft.com/en-us/library/ms534696%28v=vs.85%29.aspx

转自:http://my.oschina.net/fz04003/blog/102085

以前的项目中,一值都是只考虑IE6、7、8+FF的,今天因为测试组有个小MM的电脑是使用的Win7的64位+IE10的,所以发现代码中有个奇怪的问题,代码如下:

html
<from action="a.php" method="post" name="testFrom" id="testFrom">
新增荣誉证书:<input type="text" name="certname" value="" maxlength="20"/>
<input type="hidden" name="submitFlag" value="1"/>
<button class="savebtn" onclick="return save_cert()"/>
</from>

js
function save_cert(){
//必要的验证
$("#testFrom").submit();
return false;
}

上面的代码,在FF、IE8等浏览器上表现都是正常的,但是在IE10会奇怪的出现两次提交现象。经过仔细的调试,发现需要修改button的默认类型为button才能在IE10下只做一次提交。就是说button需要这样写:

<button type="button" class="savebtn" onclick="return save_cert()"/>

猜测,IE10以前,button的默认类型时button,但是到10以后默认类型编程submit了,所以出现了两次提交。以后写代码的时候要注意了,使用button的时候要显式的指定type类型,根据需要进行处理。

备注:查了下微软的MSDN发现如下内容
http://msdn.microsoft.com/en-us/library/ms534696%28v=vs.85%29.aspx

A Submit button has the same default behavior as a button created by using the submit type with the input object. If the ENTER key is pressed while a user is viewing a form that contains a Submit button, the form is submitted. This default behavior of a Submit button is indicated by a border surrounding the button. The border appears when any control in the form receives the focus, other than another button. If the Submit button has a name property, the button contributes a name/value pair to the submitted data.

Windows Internet Explorer 8 and later. The default value of this attribute depends on the current document compatibility mode. In IE8 Standards mode, the default value issubmit. In other compatibility modes and earlier versions of Windows Internet Explorer, the default value isbutton.

看来其实微软在IE8就已经对这个做了修改,只不过我们一直使用的是兼容模式才没有注意到这一点啊。

补充说明<另外一个奇怪的现象>
如下代码:
<form name="searchForm" id="searchForm" method="get" action="action.php">
标题:<input type="text" name="title" id="title" value=""/>
类型:<select name="itype" id="itype">
<option value="0">全部</option>
<option value="1">类型1</option>
<option value="2">类型2</option>
</select>
<button type="submit" name="submit" id="submit">提交</button>
</form>
此时必须点击提交按钮表单才能提交,而使用form的提交事件则无效。
$("#itype").change(function(){
    $("#searchForm").submit();
});
这里$("#searchForm").submit();会执行,但是表单并不会提交。
必须要把button的type改成button才行,即button必须按如下方式编写:
<button type="button" name="button" id="button">提交</button>
不知道为什么?

button按钮在IE6、7、8、9、10中处理方式并不相同[转]的更多相关文章

  1. 4、Hibenrate中HQL的10中查询方式

    二.具体事例如下: 2.0 编写如下sql语句 )); create sequence seq_teacher; insert into teacher values(seq_teacher.next ...

  2. 遭遇input与button按钮背景图失效不显示的解决办法

    笔者从事网页前端代码页面工程师已有多年,作为一个网页重构人员常常会遇到一些莫名其妙的DIV+CSS(正确的说法是XHTML+CSS)在 IE.FireFox火狐. 谷歌浏览器CHROME.苹果浏览器S ...

  3. input与button按钮背景图失效不显示的解决办法

    今天做公司的某个网站前端网页页面的时候笔者又遇到了难解决的网页前端DIVCSS代码问题,一个平时不会发生的怪事情发生了:为网页代码中的Form表单中的input 和 button 按钮标签在CSS样式 ...

  4. form中的button按钮在IE11中自动提交表单问题导致弹出框关闭之后表单被重置

    最近几天,测试系统,遇到一个兼容性问题,form中有一个button按钮,没有指定type类型,点击按钮弹出框选择值之后回填给form上的一个单行文本框,在IE6.IE7.IE8.IE9.IE10中测 ...

  5. 【html】button按钮的一些问题

    问题: button 按钮在不设置 type 属性时,在不同的浏览器作用不一样.举个例子: html: <!doctype html> <html lang="en&quo ...

  6. Android 自定义Button按钮显示样式(正常、按下、获取焦点)

    现在的用户对APP的外观看得很重要,如果APP内所有元件都用Android默认样式写,估计下面评论里就有一堆在骂UI丑的.今天学习自定义Button按钮样式.Button样式修改的是Button的背景 ...

  7. 超炫的Button按钮展开弧形动画效果

    ----------------------收藏备用  ------------------------------- 代码下载:http://download.csdn.net/detail/qq2 ...

  8. Kindeditor富文本实现textarea文本域的上传及单独button 按钮绑定(用来实现单文件上传)

    在最近项目要新增一个内容文章,文章包含一般的正文内容,其中正文中可以包含多张图片.文章最多包含一个音频文件.文章正文的上传功能我是通过textarea文本域绑定kindeditor编辑器实现的,而单独 ...

  9. 微信小程序组件解读和分析:七、button按钮

    button按钮组件说明: button,顾名思义,按钮,类似于html的button标签.我们可以设置按钮的属性,比如字体颜色大小,背景颜色等,可以给按钮绑定事件,用户点击时会触发事件. butto ...

随机推荐

  1. 判断sqlserver临时表等临时资源是否存在

    if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#TEMP'))  drop table #TEMP

  2. 批量导出表数据到CSV文件

    需求:把oracle数据库中符合条件的N多表,导出成csv文本文件,并以表名.csv为文件名存放. 实现:通过存储过程中UTL_FILE函数来实现.导出的csv文件放入提前创建好的directory中 ...

  3. [Javascript] Maybe Functor

    In normal Javascript, we do undefine check or null check: , name: "Suvi"}; var name = pers ...

  4. Python学习 之 运算符&表达式

    1.Python运算符包括:赋值运算符.算术运算符.关系运算符.逻辑运算符. 表达式是将不同的数据(包括变量.函数)用运算符号按一定规则连接起来的一种式子. 2.赋值运算符:=.+=.-=.*=./= ...

  5. Vesions ignore & ld: library not found for -l...

    1.递归删除指定目录下的 .git..svn 文件 find . -name .git | xargs rm -fr find . -name .svn | xargs rm -rf 第一条倒还不常用 ...

  6. spring源码分析之spring-messaging模块详解

    0 概述 spring-messaging模块为集成messaging api和消息协议提供支持. 其代码结构为: 其中base定义了消息Message(MessageHeader和body).消息处 ...

  7. Linux shell 脚本攻略之批量重命名

    摘自:<Linux shell 脚本攻略>

  8. [Java,MVC] SpringMVC+Spring+hibernate 框架

    转自:http://my.oschina.net/Thinkeryjgfn/blog/158951 1.准备的jar包以及配置文件如下: 2.新建一个JAVA web项目 3.建好以后出现以上包结构即 ...

  9. Nodejs的mysql模块学习(一)

    介绍 mysql npm包 是一个nodejs的模块,由JavaScript编写 安装 npm install mysql 建立连接 var mysql = require('mysql');//引用 ...

  10. linux云计算集群架构学习笔记:系统文件的目录结构

    文件的基本管理和XFS文件系统备份恢复 1.1  Linux系统目录结构,相对/绝对路径. 1.2  创建/复制/删除文件,rm -rf / 意外事故 1.3 查看文件内容 1.4 xfs文件系统的备 ...