button按钮在IE6、7、8、9、10中处理方式并不相同[转]
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中处理方式并不相同[转]的更多相关文章
- 4、Hibenrate中HQL的10中查询方式
二.具体事例如下: 2.0 编写如下sql语句 )); create sequence seq_teacher; insert into teacher values(seq_teacher.next ...
- 遭遇input与button按钮背景图失效不显示的解决办法
笔者从事网页前端代码页面工程师已有多年,作为一个网页重构人员常常会遇到一些莫名其妙的DIV+CSS(正确的说法是XHTML+CSS)在 IE.FireFox火狐. 谷歌浏览器CHROME.苹果浏览器S ...
- input与button按钮背景图失效不显示的解决办法
今天做公司的某个网站前端网页页面的时候笔者又遇到了难解决的网页前端DIVCSS代码问题,一个平时不会发生的怪事情发生了:为网页代码中的Form表单中的input 和 button 按钮标签在CSS样式 ...
- form中的button按钮在IE11中自动提交表单问题导致弹出框关闭之后表单被重置
最近几天,测试系统,遇到一个兼容性问题,form中有一个button按钮,没有指定type类型,点击按钮弹出框选择值之后回填给form上的一个单行文本框,在IE6.IE7.IE8.IE9.IE10中测 ...
- 【html】button按钮的一些问题
问题: button 按钮在不设置 type 属性时,在不同的浏览器作用不一样.举个例子: html: <!doctype html> <html lang="en&quo ...
- Android 自定义Button按钮显示样式(正常、按下、获取焦点)
现在的用户对APP的外观看得很重要,如果APP内所有元件都用Android默认样式写,估计下面评论里就有一堆在骂UI丑的.今天学习自定义Button按钮样式.Button样式修改的是Button的背景 ...
- 超炫的Button按钮展开弧形动画效果
----------------------收藏备用 ------------------------------- 代码下载:http://download.csdn.net/detail/qq2 ...
- Kindeditor富文本实现textarea文本域的上传及单独button 按钮绑定(用来实现单文件上传)
在最近项目要新增一个内容文章,文章包含一般的正文内容,其中正文中可以包含多张图片.文章最多包含一个音频文件.文章正文的上传功能我是通过textarea文本域绑定kindeditor编辑器实现的,而单独 ...
- 微信小程序组件解读和分析:七、button按钮
button按钮组件说明: button,顾名思义,按钮,类似于html的button标签.我们可以设置按钮的属性,比如字体颜色大小,背景颜色等,可以给按钮绑定事件,用户点击时会触发事件. butto ...
随机推荐
- TFS 图标意思
小人:文件被其他人签出 对号:文件被自己签出 锁: 文件已经被签入 加号:新增加一个文件
- QM课程02-外部功能
质量计划 · 对质量计划和检验计划进行基本数据的管理 · 物料说明 · 检验计划 质量检验 · 触发检验 · 具有检验计划选择和样本计算的检验处理 · 打印采样和检验的车间文档 · 记录结果和缺陷 · ...
- FZU 2169 shadow (用了一次邻接表存边,树形DP)
Accept: 28 Submit: 97 Time Limit: 1000 mSec Memory Limit : 32768 KB Problem Description YL是shadow国的国 ...
- 让你的PHP程序真正的实现多线程(PHP多线程类)(转)
通过WEB服务器来实现PHP多线程功能. 当然,对多线程有深入理解的人都知道通过WEB服务器实现的多线程只能模仿多线程的一些效果,并不是真正意义上的多线程. 但不管怎么样,它还是能满足我们的一些需要的 ...
- pt-online-schema-change使用说明、限制与比较
http://seanlook.com/2016/05/27/mysql-pt-online-schema-change/ http://blog.itpub.net/22664653/viewspa ...
- sql server where、group by、order by 执行顺序
2012-02-07 19:39 先where 条件1,再 group by 条件2再 order by 条件3 如果声明了 GROUP BY 子句,输出就分成匹配一个或多个数值的不同组里. 如果出现 ...
- Windows Azure 微软公有云体验(三) IIS中文编码解决方案
Windows Azure 微软公有云已经登陆中国有一段时间了,现在是处于试用阶段,Windows Azure的使用将会给管理信息系统的开发.运行.维护带来什么样的新体验呢? Windows Azur ...
- Linux学习之路:命令别名、历史记录和命令查找执行顺序
一.命令别名 alias rm='rm –i':删除命令时会随时出现提示;alias vi=vim alias 不加参数,显示系统内所以命令别名 unalias 取消别名 二.历史命令 history ...
- ZOJ 3209 Treasure Map (Dancing Links)
Treasure Map Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Submit S ...
- android Animation笔记
日历 公告 关于动画的实现,Android提供了Animation,在Android SDK介绍了2种Animation模式: 1. Tween Animation:通过对场景里的对象不断做图 ...