I have a tag like this
<a onlclick="return isExecute();" data-href="/otherPage">
How can I do to prevent redirect to /otherPage
when isExecute()
return false.
尝试这个 :
<a onlclick="return isExecute();" data-href="javascript:if(isExecute()){ return '/otherPage'; }">
<a onclick="return isExecute(event);" data-href="/otherPage">
Write isExecute()
function like this.
function isExecute(e) {
e.preventDefault();
/* Your Code */
}
You can prevent the default action of the anchor by doing this
<a onlclick="redirect()" data-href="/otherPage">
then on a function
function redirect(e) {
if(!isExecute()) {
e.preventDefault();
}
}
or if your isExecute function is async then you can preventDefault at first and pass the data-href and if returns true then redirect
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.