Why is the onClick event triggered twice?

前端 未结 10 1370
夕颜
夕颜 2021-02-05 02:40

I have the following html:


    
&         


        
10条回答
  •  长发绾君心
    2021-02-05 02:59

    Here button click is triggered. Since the button is inside the span and onclick event is defined for span the two alert are happened.

    One is by the button 
    

    and

    other by its parent(parent have onclick event and button click is triggered).

    To avoid two alert, use this

    
        
    
    

提交回复
热议问题