Why is the onClick event triggered twice?

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

I have the following html:


    
&         


        
10条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-05 03:11

    This thread will help answer the 'why' of it.

    A better way would be to just assign a click handler to the element so as to keep your Javascript abstracted out of the HTML:

    http://jsfiddle.net/v4100zke/3/

    $('#test1').click(function() {
        alert('Boem')
    });
    

    Hope that helps.

提交回复
热议问题