X龙@China .Net 'blog

需要的不仅仅是工作,而是通过努力得来的美好将来。
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

按钮提交事件处理(以下方法兼容ie,firefox,chrome)

Posted on 2012-07-28 11:26  X龙  阅读(1737)  评论(0编辑  收藏  举报
1. input[type="button"],input[type="button"]
前提函数:function myfunction(e){};
当点击按钮需要验证,并控件表单是否提交时,使用onclick="myfunction(event);",
使用event的原因:是为了兼容firefox,firefox会生成function click(event){myfunction(event);},
如果你写成onclick="myfunction(e);",firefox中会生成function click(event){myfunction(e);},e没有定义所以会出错。
2.一个按钮绑定多个事件处理程序时,需要根据上一个事件处理程序是否通过验证的结果时,在myfunction中设置
function myfunction(e){if(通过验证){e.returnValue = true};else{e.returnValue = false;}},在第二个事件处理程序中可以通过e.returnValue来判断上一个事件处理程序是否通过验证。说明:firefox的event中不存在returnValue,不存在时为它赋值,会创建该属性。
点击这里给我发消息http://wp.qq.com/index.html