如何确保在加载外部HTML后发出警报?
function changeContent(){
$('#contentmain').load("contentmain.html", function(){
alert("something");
}
)}
我一直在玩$(文件).ready,但到目前为止没有运气。
非常感谢!
更新
这段代码的结果是它取决于(我不知道的是什么):有时候警报会先出现,有时会出现第二次......
答案 0 :(得分:3)
您的代码是对的。
Callback Function
If a "complete" callback is provided, it is executed after post-processing and HTML insertion has been performed. The callback is fired once for each element in the jQuery collection, and this is set to each DOM element in turn.
答案 1 :(得分:0)
尝试.load()功能。
$('#iframeID').load(function(){
// I am totally loaded and lets begin the hunt now.
});
或者,如果您通过ajax加载内容,则可以使用.ajaxComplete
$(document).ajaxComplete(function(){
// ajax call has completed and lets begin the hunt now.
});