Two differents OnClick on two divs, one over the other

后端 未结 6 1559
心在旅途
心在旅途 2020-12-06 06:50

I have two divs, a big one and a smaller over the other, each div has its own OnClick method. The problem I have is when I clicked the smaller div, the big div\'s OnClick me

6条回答
  •  情话喂你
    2020-12-06 07:15

    You're running into a common case of event propagation. Check out quirksmode.org to get the full details on what exactly is happening. Basically, what you need to do in the smaller div's click handler is this:

    if (!e) var e = window.event;
    e.cancelBubble = true;
    if (e.stopPropagation) e.stopPropagation();
    

提交回复
热议问题