Disable textbox autofocus in javascript

Is there a way in Javascript to force the autofocus of the text field to be disabled when the page loads?

I know the focus () method, but not how to disable it. My actual problem is that autofocusing in a modal window causes the window to appear with the scroll bar halfway down and scrolls to the first input field, whereas I would like to completely disable this.

Thanks!

+6
source share
4 answers

You can use .blur() ,

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

If you want to turn off focus on all text fields,

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

You can use in jQuery

 $(function(){ $('input').blur(); }); 
+5
source

Something in the Javascript code that you use when setting focus on the field is not automatic behavior. Just find it and unplug it.

+2
source

You can forcefully focus on the object above on the page when loading.

+1
source

Source: https://habr.com/ru/post/893187/


All Articles