How to call multiple JavaScript functions in onclick event?

后端 未结 11 817
梦如初夏
梦如初夏 2020-11-22 06:25

Is there any way to use the onclick html attribute to call more than one JavaScript function?

11条回答
  •  逝去的感伤
    2020-11-22 07:20

    var btn = document.querySelector('#twofuns');
    btn.addEventListener('click',method1);
    btn.addEventListener('click',method2);
    function method2(){
      console.log("Method 2");
    }
    function method1(){
      console.log("Method 1");
    }
    
    
    
      
      
      Pramod Kharade-Javascript
    
    
    
    
    

    You can achieve/call one event with one or more methods.

提交回复
热议问题