Uno*_*Ame 2 html javascript onclick
我有一个div是有一个onclick隐藏的div.
如果我内部有链接div,则链接不起作用,因为onclick窃取了点击.
期望的结果:如果在div内的任何地方点击链接,则div被隐藏.如果在链接上单击,则我希望链接在_blank窗口中打开,并且div保持可见.
有没有办法用javascript处理这个?
document.getElementById('yourlinksid').onclick = function(e){
// ... pop your window ...
/* the following prevents the event from "bubbling up"
to the div's event handler */
if(!e.stopPropagation) {
e.cancelBubble = true;
return;
}
e.stopPropagation();
};
Run Code Online (Sandbox Code Playgroud)
验证: