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

后端 未结 3 1138
一向
一向 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:01

    What version IE? What's your DocType set to? is it strict, standards or quirks mode? Any javascript errors appearing (check the status bar bottom left for a little yellow warning sign) ? Enable error announcing for all errors via Tools > Options > Advanced.

    Oisin

    0 讨论(0)
  • 2021-01-28 01:12

    The question is already answered by 17 of 26. I just want to point out, that Prototype has native mechanism for this: Function.defer()

    0 讨论(0)
  • 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.

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