为什么我的jQuery checkbox.change事件只触发在IE上的leavefocus,但他们发生onclick在FF? [英] Why do my jQuery checkbox.change events only fire on leavefocus in IE but they happen onclick in FF?

查看:188
本文介绍了为什么我的jQuery checkbox.change事件只触发在IE上的leavefocus,但他们发生onclick在FF?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

    $(".feature").change(function(){
        getProductSelections();
    });

ARRRGHH !!

ARRRGHH!!

推荐答案

网站错误轨道:


onchange事件可以附加(内联或作为事件处理程序)到任何表单元素。每当表单字段的值更改时触发。不幸的是,IE的行为是有点奇怪,因为对于复选框或单选按钮字段,事件不会触发时,它应该(当你单击要选择的选项时),而是它只有当你点击页面/窗体上的其他地方,或者如果你明确调用blur();

The onchange event can be attached (inline or as an event handler) to any form element. It fires whenever the value of the form field changes. Unfortunately, the behavior is a bit strange in IE, in that for a checkbox, or a radio button field, the event doesn't fire when it is supposed to (right when you click the option you want to choose), but instead it only fires, when you click elsewhere on the page/form, or if you explicitly call blur(); on the field.

建议的解决方法是:

<input type="radio" name="foo" value="Green" onclick="alert(this.value);"/>Green
<input type="radio" name="foo" value="Blue" onclick="alert(this.value);"/>Blue

这篇关于为什么我的jQuery checkbox.change事件只触发在IE上的leavefocus,但他们发生onclick在FF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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