How do I set the focus to the first input element in an HTML form independent from the id?

前端 未结 17 1907
遇见更好的自我
遇见更好的自我 2020-12-08 01:33

Is there a simple way to set the focus (input cursor) of a web page on the first input element (textbox, dropdownlist, ...) on loading the

17条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-08 02:16

    The most comprehensive jQuery expression I found working is (through the help of over here)

    $(document).ready(function() {
        $('input:visible:enabled:first').focus();
    });
    

提交回复
热议问题