Disable Text Field Autofocus in Javascript

一笑奈何 提交于 2019-12-05 09:30:29

You can use .blur() ,

var elelist = document.getElementsByTagName("input");
for(var i = 0; i < elelist.length; i++){
    elelist[i].blur();
}

If you want to disable focus on all the textfields,

var elelist = document.getElementsByTagName("input");
for(var i = 0; i < elelist.length; i++){
    elelist[i].addEventListener("focus", function(){
        this.blur();
    });
}

You can use in jQuery

$(function(){
    $('input').blur();
});

There's something in the Javascript code you're using that's setting the focus to the field, this is not an automatic behavior. Just find that and disable it.

You could force focus on an object higher in the page on load.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!