如何使各种表单元素的 onChange 事件冒泡到 Internet Explorer 中的父表单对象?当在 IE 中选择框、单选按钮...几乎所有...更改时,不会触发父表单的 onChange。我的表单是动态变化的,因此很难通过监听每个子表单元素来破解它。
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');
}
);
顺便说一句,我正在使用原型(prototype)框架。它不应该为我处理跨浏览器的差异吗?
最佳答案
我不得不为 IE 使用 hack。我手动让所有子表单元素触发 onChange 回调,而不是让父表单执行它。我希望有一个更清洁的解决方案。
$('myForm').select('input', 'radio', 'textarea').each(
function(formElement) {
formElement.observe(
'change',
function() {
alert('changed');
}
);
}
);
关于javascript - 在 Internet Explorer 中使表单元素 onchange 气泡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5146784/