gpt4 book ai didi

javascript - JSONP 回调中的 PreventDefault

转载 作者:行者123 更新时间:2023-11-28 21:10:44 26 4
gpt4 key购买 nike

我想在 jsonp 的回调中使用事件的 PreventDefault 方法。我必须使用纯javascript。我已经有一个模拟 jsonp 请求的函数。这就是我正在做的事情:

var evt_temp = null;

function onContextMenu(event)
{
evt_temp = event;
jsonp
({
url: "someurl",
params: "someparams",
callback: "cb"
});
}

function cb(response)
{
if (something == true)
{
evt_temp.preventDefault();
evt_temp = null;
}
}

我的解决方案有效,但我觉得这不是一个好主意,将事件存储在 var 上。有人知道更好的方法吗?

最佳答案

这并不反对它,但就你而言,它似乎有点无用。当您使用异步回调时,preventDefault() 将在默认浏览器行为发生后调用。仅当您直接在事件的回调函数中使用它时才有意义。

关于javascript - JSONP 回调中的 PreventDefault,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8761707/

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