在Internet Explorer中创建表单元素onchange bubble [英] Make form elements onchange bubble in Internet Explorer

查看:154
本文介绍了在Internet Explorer中创建表单元素onchange bubble的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使各种表单元素的onChange事件冒泡到Internet Explorer中的父表单对象?当选择框,单选按钮,......几乎所有...... IE中的更改时,父表单的onChange不会被触发。我的表单是动态变化的,所以通过聆听每个子表单元素很难破解它。

How do you make the onChange event of various form elements bubble up to the parent form object in Internet Explorer? When select boxes, radio button, ... almost anything ... changes in IE, the parent form's onChange is not fired. My forms are dynamically changing so it will be hard to hack it by listening on each and every child form element.

HTML

<form id="myForm">
 <select>
  <option>uno</option>
  <option>dos</option>
 </select>
 <input type="radio" name="videoDevice" value="tres" checked="checked" />
 <input type="radio" name="videoDevice" value="cuatro" />
</form>

JS

$('myForm').observe(
 'change', 
 function() {
  // this only runs in non-IE browsers
  alert('the form changed');
 }
);

BTW,我正在使用Prototype框架。难道它不应该为我处理跨浏览器的差异吗?

BTW, I'm using the Prototype framework. Shouldn't it have handled the cross-browser differences for me?

推荐答案

我不得不使用IE浏览器。我手动使所有子表单元素触发onChange回调而不是让父表单执行它。我希望有一个更清洁的解决方案。

I had to use a hack for IE. I manually made all the child form elements trigger the onChange callback rather than have the parent form do it. I wish there was a cleaner solution.

$('myForm').select('input', 'radio', 'textarea').each(
 function(formElement) {
  formElement.observe(
   'change', 
   function() {
    alert('changed');
   }
  );
 }
);

这篇关于在Internet Explorer中创建表单元素onchange bubble的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆