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. C++ CheckBox_Porerty

    主题 1. s       Caption属性 CheckBox   CheckDlgButton BOOL CheckDlgButton(      HWND hDlg,      // handl ...

  2. java 覆盖hashCode()深入探讨 代码演示样例

    java 翻盖hashCode()深入探讨 代码演示样例 package org.rui.collection2.hashcode; /** * 覆盖hashcode * 设计HashCode时最重要 ...

  3. [Angular 2] Inject Service with "Providers"

    In this lesson, we’re going to take a look at how add a class to the providers property of a compone ...

  4. swift3.0 中NSNotification 的使用

    swift3.0 有很大变化,其中之一就是NSNotification使用跟原来不一样,以前NSNotification name是String:3.0中定义了一个类型NSNotification.n ...

  5. StarlingMVC简介,原理解说及示例源码

    StarlingMVC简介 StarlingMVC是一个为使用Starling来开发游戏的MVC框架.这个框架的特性方面,很像Swiz和RobotLegs,原理亦像Mate.其特性列表如下: 依赖注入 ...

  6. ASP.NET 去除所有HTML标记的方法

    using System.Text.RegularExpressions /// <summary> /// 去除HTML标记 /// </summary> /// <p ...

  7. Helpers\GeoCode

    Helpers\GeoCode This function connects to google maps and retrieves the lat/lon of the address provi ...

  8. 琐碎-关于StringTokenizer工具

    属于:java.util包 构造函数: 1. StringTokenizer(String str):构造一个用来解析str的StringTokenizer对象.java默认的分隔符是“空格”.“制表 ...

  9. SQL Server 之 在与SQLServer建立连接时出现与网络相关的或特定于实例的错误

    背景:在用数据库时,打开SQL Server 2008 R2 的 SQL Server Management Studio,输入sa的密码发现,无法登陆数据库,提示信息如上: 解决方案: 1.打开Sq ...

  10. MapReduce中的作业调度

    MapReduce是hadoop提供一个可进行分布式计算的框架或者平台,显然这个平台是多用户的,每个合法的用户可以向这个平台提交作业,那么这就带来一个问题,就是作业调度. 任何调度策略都考虑自己平台调 ...