How to consume button click inside tag to prevent link being followed?

前端 未结 5 1957
傲寒
傲寒 2021-01-27 01:49

I\'ve added a button inside a link tag, with a little cross image, that I will eventually use to actually remove that element without it following the link also:

<
5条回答
  •  遥遥无期
    2021-01-27 02:05

    You need return false; at the end of detectClick and you need to return detectClick on your onclick event.

    Explanation: The return value of the event handler tells the browser whether the default browser action should occur. Since clicking on your button by default triggers the click event of its parent, the link, return false; will prevent that default from happening, which is your exact intention.

提交回复
热议问题