如何将值传递给 load() 的完整函数

How to pass a value to the complete function of load()

我想传递一个值以在 jquery 中的 load() 的完整函数中使用,如下所示:

$( "#myDiv").load( "myFile.html", function( response, status, xhr ) {
    //I need the value here
}

有什么想法吗?

谢谢,对不起我的英语。

load 完成回调将是一个 闭包 在您创建它的上下文中,这意味着它可以访问您创建它的范围内的变量.例如,如果您有

function doTheLoad(someUsefulThing) {
    $( "#myDiv").load( "myFile.html", function( response, status, xhr ) {
        console.log(someUsefulThing);
    });
}

...即使 doTheLoad 已经返回,您也可以使用 someUsefulThing,因为闭包(回调函数)保留对它的引用(间接)。