简体   繁体   中英

can't click a link after event.preventDefault

Question:

At a project(phonegap at android), I listen the touch event as MDN guide :

document.addEventListener("touchstart", handleStart, false);    
function handleStart(evt){    
     evt.preventDefault();    
     .......    
}    

But after that, the links can't response to click event any more.

Because you basically took away the "default behavior" of the document. Is there a reason why you have that in your code. You are adding it to the whole document.

Don't put the addEventListener on your whole document, put it on an element within the document.

evt.preventDefault(); removes the events default behaviour. If you click a button which default action is to propagate the link, the preventDefault(); will prevent this from happening.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM