IE8& IE7 onchange事件只有在重复选择后才会触发 [英] IE8 & IE7 onchange event is triggered only after repeated selection

查看:94
本文介绍了IE8& IE7 onchange事件只有在重复选择后才会触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组带有onchange处理程序的电台:

 < input type =radioname =Q12 value =radioid =Q12_0onchange =nextPnl('Q12');> 
< br />
< input type =radioname =Q12value =radioid =Q12_1onchange =nextPnl('Q12');>


function nextPnl(did)
{
document.write(did);

}

问题是,在IE8& IE7中,onchange事件只有在重复选择后才会触发。



请在IE的开发工具[浏览器模式]中查看本演示IE8:
http://jsfiddle.net/3zwur/2/

解决方案

这是由于IE7和IE8的更改事件的错误。您应该倾听点击事件。

如此表格怪异模式,单选按钮和复选框上的更改事件在IE7和IE8中相当麻烦。



您可以像这样收听点击事件: p>

 < input type =radioname =Q12value =radioid =Q12_0onclick =nextPnl 'Q12');> 
< br>
< input type =radioname =Q12value =radioid =Q12_1onclick =nextPnl('Q12');>

然后你的小提琴的叉子: http://jsfiddle.net/T7VYL/

通常,使用一个JavaScript库,如 JQuery YUI 让你的生活更轻松,尽管从我的测试来看,他们并没有修复旧版本IE中的这个bug。



如果您仍然想要听更改事件,可以部署此修补程序: http:// www .ridgesolutions.ie / index.php文件/ 2011/03/02 / IE8,恰克 - jQuery的事件不烧/ 。基本上它会监听点击事件,然后导致元素触发一个更改事件。



正如asker的小提琴演示: http://jsfiddle.net/3zwur/3


I have a group of radio with an onchange handler:

<input type="radio" name="Q12" value="radio" id="Q12_0"  onchange="nextPnl('Q12');">
<br/>
<input type="radio" name="Q12" value="radio" id="Q12_1"  onchange="nextPnl('Q12');">
         ​

function nextPnl(did)
{
document.write(did);

}​

The problem is that in IE8 & IE7, the onchange event is triggered only after repeated selection.

Please view this demo in IE's Developer Tools [Browser Mode] IE8: http://jsfiddle.net/3zwur/2/

解决方案

This is due to a bug with IE7 and IE8's change events. You should instead listen to the click event.

As shown in this table on quirks mode, the change event on radio buttons and checkboxes is quite buggy in IE7 and IE8.

You can listen to the click event like so:

<input type="radio" name="Q12" value="radio" id="Q12_0"  onclick="nextPnl('Q12');">
<br>
<input type="radio" name="Q12" value="radio" id="Q12_1"   onclick="nextPnl('Q12');">

And a fork of your fiddle: http://jsfiddle.net/T7VYL/

Usually, using a javascript library such as JQuery and YUI make your life easier, although from my testing, they do not fix this bug in older versions of IE.

If you would still like to listen to the change event, you can deploy this fix: http://www.ridgesolutions.ie/index.php/2011/03/02/ie8-chage-jquery-event-not-firing/. Basically it listens for the click event, and then causes the element to fire a change event.

As demonstrated by the asker's fiddle: http://jsfiddle.net/3zwur/3

这篇关于IE8&amp; IE7 onchange事件只有在重复选择后才会触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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