Adding an input field to the dom and focusing it in IE

后端 未结 3 1197
一向
一向 2021-01-28 00:38

I am trying to make a div, that when you click it turns into an input box, and focuses it. I am using prototype to achieve this. This works in both Chrome and Firefox, but not i

3条回答
  •  情书的邮戳
    2021-01-28 01:14

    My guess is that IE hasn't updated the DOM yet when you make the call to focus(). Sometimes browsers will wait until a script has finished executing before updating the DOM.

    I would try doing the update, then doing

    setTimeout("setFocus", 0);
    
    function setFocus()
    {
        editElement.focus();
    }
    

    Your other option would be to have both items present in the DOM at all times and just swap the style.display on them depending on what you need hidden/shown at a given time.

提交回复
热议问题