【问题标题】:Event Handlers not being invoked in IE 9IE 9 中未调用事件处理程序
【发布时间】:2015-05-08 16:44:04
【问题描述】:

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

$(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();
    });
});

我的代码在 Chrome 中运行良好,但在 IE-9 中调用的是默认事件处理程序。

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

【问题讨论】:

  • 你能发布完整的代码吗?我什至没有在 jsfiddle 中使用它。

标签: javascript dom event-handling internet-explorer-9


【解决方案1】:

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

可以在here 找到它支持的事件列表。要在 IE 中执行此操作,您必须使用除 <option><select> 之外的其他类型元素使用 JS/CSS 实现您自己的选择框。

我建议使用<ul><li>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-24
    • 2023-03-11
    • 2015-12-18
    • 1970-01-01
    相关资源
    最近更新 更多