IE 9中未调用事件处理程序

时间:2021-11-08 00:05:57

I am trying to add event handlers to the option elements contained inside a select box. The relevant code is as follows:

我正在尝试将事件处理程序添加到选择框中包含的选项元素。相关代码如下:

$(document).ready(function(){

    $('.custom_select_option_1').mousedown(function(event){
        event.preventDefault();
        var opt= event.target;
        var scroll_offset= opt.parentElement.scrollTop;
        opt.selected= !opt.selected;
        opt.parentElement.scrollTop= scroll_offset;
        update_selections(opt.parentElement);
    });
    $('.custom_select_option_1').mousemove(function(event){
        event.preventDefault();
    });
});

My code works fine in Chrome, but in IE-9 the default event handlers are invoked instead.

我的代码在Chrome中工作正常,但在IE-9中,默认的事件处理程序会被调用。

How can I adapt this code so that it works in IE-9?

如何调整此代码以使其在IE-9中运行?

1 个解决方案

#1


Unfortunately, Internet Explorer does not support the mousedown event for option elements.

遗憾的是,Internet Explorer不支持选项元素的mousedown事件。

A list of the events it does support can be found here. To do this in IE, you have to implement your own select box with JS/CSS using some other type of elements besides <option> and <select>.

可以在此处找到它支持的事件列表。要在IE中执行此操作,您必须使用除

I suggest using <ul> and <li>.

我建议使用

#1


Unfortunately, Internet Explorer does not support the mousedown event for option elements.

遗憾的是,Internet Explorer不支持选项元素的mousedown事件。

A list of the events it does support can be found here. To do this in IE, you have to implement your own select box with JS/CSS using some other type of elements besides <option> and <select>.

可以在此处找到它支持的事件列表。要在IE中执行此操作,您必须使用除

I suggest using <ul> and <li>.

我建议使用