我有一个链接:
链接
使用::
$('#myID').click(function(){
if($("#myCheckbox").is(":checked")) {
alert('Yes it is...'); //continue as normal
}
else {
alert('Not checked');
//exit do not follow the link
}
...
那么//exit 不跟随链接可能吗?
最佳答案
尝试使用 event.preventDefault()
$('#myID').click(function(e) {
if ($("#myCheckbox").is(":checked")) {
alert('Yes it is...');
}
else {
alert('Not checked');
e.preventDefault(); // this prevents the standard link behaviour
}
}
关于javascript - JQuery onclick 条件停止链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8789552/