代码之家  ›  专栏  ›  技术社区  ›  thetoolman

当<select>处于活动状态并处于下拉状态时,使事件在iE6中触发

  •  0
  • thetoolman  · 技术社区  · 16 年前

    我很确定这只是iE6的一个限制,但我想我最好问问以防万一:

    <body>
        <h1>Select + event test</h1>
        <div>   
            <select>
                <option>ABC</option>
                <option>123</option>
            </select>
            <span id="eventSrc">Event Source</span>
        </div>
        <div id="log"></div>
    
        <script type="text/javascript">
            var log = $("#log");
            $("#eventSrc").bind("mouseover mouseout mouseenter mouseleave", function(event){
                log.append(event.type + "<br/>");
            })
        </script>
    </body>
    

    在所有现代浏览器中,日志都会记录鼠标*事件,即使在“下拉”选择时也是如此。在iE6中,当active+下降时,它似乎不会触发事件。

    纯JS解决方案也很受欢迎,jQuery对于我的演示非常简洁:)

    1 回复  |  直到 16 年前
        1
  •  1
  •   scunliffe    16 年前

    我想你运气不好。IE在选择列表方面出了名的问题。

    例如 you can't bind events to the options disable them (IE8之前)和 trying to modify the contents (例如,选项)在打开时失败。