Adding Event Listeners on Elements - Javascript

前端 未结 5 1241
误落风尘
误落风尘 2020-12-03 17:22

Are there ways for me to listen for onblur or onclick events in javascript from an onload function? instead of doing it in the element itself.



        
5条回答
  •  情歌与酒
    2020-12-03 17:54

    The better way it's used DOM (works perfectly) like this. Firs write Yours function/class and use it in:

    document.addEventListener('DOMContentLoaded', function(){
      // put here code
    });
    
    
    
      
    
      
        
      
    

    It's doesn't matter where You used this few lines. You can put it in head or in body.

提交回复
热议问题