Blur a select after change in Internet Explorer 6

后端 未结 2 740
醉话见心
醉话见心 2021-01-07 15:18

Simple question really. This works in all but IE6:





                        
    
提交评论

  • 2021-01-07 16:07
    <select id="test" onchange="blur()">
    

    You want to blur the select, not the window (which acts as the global object, so this is the same as window.blur()).

    <select id="test" onchange="this.blur();">
    

    Works in all but IE6 due to a bug. You could get around it by focusing something else:

    <a href="#" id="x"></a>
    <select id="test" onchange="var x= document.getElementById('x'); x.focus(); x.blur();">
    

    BUT! Either way, don't do this. You'll break keyboard accessibility for the select (since pressing up/down immediately sends a change event). This is the same problem that faces drop-downs abused as navigation.

    0 讨论(0)
  • 提交回复
    热议问题