gpt4 book ai didi

jquery - 我可以在 PreventDefault() 之后执行链接吗?

转载 作者:行者123 更新时间:2023-12-03 22:12:28 26 4
gpt4 key购买 nike

代码:

$('#myLink').click(function (e) {
e.preventDefault();

...

if (someCondition) {
... code ...
} else {
... execute the link
}
});

我想,如果 someCondition 为 false,则执行链接的原始 href(因此,转到该链接,更改页面)。这可能吗?

最佳答案

$('#myLink').click(function (e) {
e.preventDefault();

...

if (someCondition) {
//do stuff
} else {
location.href = $(this).attr('href');
}
});

关于jquery - 我可以在 PreventDefault() 之后执行链接吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10945478/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com