代码:
$('#myLink').click(function (e) {
e.preventDefault();
...
if (someCondition) {
... code ...
} else {
... execute the link
}
});
Run Code Online (Sandbox Code Playgroud)
我想,如果someCondition是假的话,执行链接的原始href(所以,去那个链接,改变页面).这有可能吗?
coo*_*guy 19
$('#myLink').click(function (e) {
e.preventDefault();
...
if (someCondition) {
//do stuff
} else {
location.href = $(this).attr('href');
}
});
Run Code Online (Sandbox Code Playgroud)
只需preventDefault在if/else语句中移动:
$('#myLink').click(function (e) {
...
if (someCondition) {
e.preventDefault();
... code ...
} else {
... execute the link
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9804 次 |
| 最近记录: |