Setting focus on an HTML input box on page load

后端 未结 4 785
渐次进展
渐次进展 2020-12-13 11:59

I\'m trying to set the default focus on an input box when the page loads (example: google). My page is very simple, yet I can\'t figure out how to do this.

This is w

4条回答
  •  一生所求
    2020-12-13 12:15

    This is one of the common issues with IE and fix for this is simple. Add .focus() twice to the input.

    Fix :-

    function FocusOnInput() {
        var element = document.getElementById('txtContactMobileNo');
        element.focus();
        setTimeout(function () { element.focus(); }, 1);
    }
    

    And call FocusOnInput() on $(document).ready(function () {.....};

提交回复
热议问题