gpt4 book ai didi

jquery - 使用 jQuery PreventDefault() 如何执行默认操作?

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

我有以下代码:

$('a.confirm').click(function(e) {
e.preventDefault();
var answer = confirm("Are you sure?")
if (answer){
// do the default action
}
});

如果用户确认,我必须输入什么代码才能执行默认操作?

最佳答案

$('a.confirm').click(function(e) {
var answer = confirm("Are you sure?")
if (answer){
// do the default action
} else {
e.preventDefault();
}
});

$('a.confirm').click(function(e) {
var answer = confirm("Are you sure?")
if (!answer){
e.preventDefault();
}
});

或者甚至只是

$('a.confirm').click(function(e) {
return confirm("Are you sure?");
});

关于jquery - 使用 jQuery PreventDefault() 如何执行默认操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4269024/

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