< select>上的jQuery change()和firefox [英] jQuery change() on <select> and firefox

查看:159
本文介绍了< select>上的jQuery change()和firefox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个下拉菜单,当它更改时触发ajax调用:

I have a dropdown that triggers an ajax call when its changed:

$('.travel-to').change(function(){  
    $.ajax({
        type: "GET",
        url: "/inc/rates/rates-viewer.php",
        data: "shtech=y&c_name="+escape($(this).val()),
        success: function(html){
            $(".rates-viewer").html(html);
            $(".rates-viewer tr.numbers td").css({ opacity: 0 }).fadeTo("slow",1);
        }
    });
});

我的问题是,在Firefox中,使用上/下光标键循环浏览下拉列表选项,不会触发js onChange()事件。在IE中可以。

My problem is, in Firefox, using the up/down cursor keys to cycle through the dropdown options, doesn't trigger the js onChange() event. It's ok in IE.

如何让Firefox看到一个 onChange 的上/下光标?我可以做一个事件还是在事件上做一个 onChange 或按键触发器相同的东西?

How can I make Firefox see the up/down cursors as an onChange? Can I do an either/or on the event, to make either an onChange or a keypress trigger the same thing?

谢谢。

推荐答案

你实际上正在利用IE中的一个错误。 Firefox正确支持onChange,因为它不会在浏览器失去选择字段的焦点之前触发。 (我回答问题昨天关于这个问题,实际上。)使用onChange与select是一件很危险的事情,特别是因为没有办法键盘只有用户跳过一些选项。 (除此之外,鼠标滚轮似乎旋转多个答案,但实际上它在IE上通过的每个条目实际上触发onChange。)

You're actually taking advantage of a bug in IE. Firefox supports onChange correctly, as it's not supposed to fire until the browser loses focus of the select field. (I answered a question yesterday about this very issue, in fact.) It's actually kind of dangerous to use onChange with a select, especially because there's no way for keyboard only users to skip some options. (On top of that, the mouse wheel seems to spin by multiple answers, but it actually fires onChange for each entry it passes by on IE.)

如果你真的希望每当有人按下或关闭该事件时,我会挂起onKeyPress或onKeyDown事件,只要按下上或下键即可触发。

If you really want the event to fire whenever someone presses up or down, I would hook into the onKeyPress or onKeyDown events to fire whenever the "up" or "down" key is pressed.

这篇关于< select>上的jQuery change()和firefox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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