如何在 jquery 加载后调用函数

How do I call a function after a jquery load

我使用 jquery 加载在我的 body 页面中放置一个 html 结构。之后,我想调用另一个函数来显示 table headers。假设运行加载后的功能。但是,当我在加载参数中插入完成函数时,加载永远不会完成。如果我把它拿出来,我就不能调用我的函数了。

app.js

function insertHTML(){
  var thead = document.getElementByID("thead");
  thead.innerHTML = theadOutput(); //function works fine
}

window.onload = function(){
  $(body).load(body_loc, insertHTML());
}

您需要传递函数引用,而不是调用它:

$(body).load(body_loc, insertHTML);