How to make input autofocus in internet explorer?

前端 未结 5 898
南旧
南旧 2020-12-03 18:17

Please check out my jsfiddle

http://jsfiddle.net/WK2N3/1/

How can I make this on autofocus like it is for chrome, safari, opera and firefox for IE?

5条回答
  •  不知归路
    2020-12-03 19:17

    Here's a one-liner (well, one line of actual logic) that uses jQuery to make autofocus work in IE. It bails out if the focus is already set--in other words, in any HTML5-capable browser.

    $(function() {
      $('[autofocus]:not(:focus)').eq(0).focus();
    });
    

    I explained how it works in my blog. And here is an updated jsFiddle that works in IE.

提交回复
热议问题