如何在时间后加载 div 内容。设置超时(), 加载()
How to load div content after time. SetTimeout(), Load()
我需要在单击按钮 2 秒后加载 div 的内容。内容是其他 html 文件。当我使用
setTimeout($(".frame").load(this.href),5000);
div 立即加载文件内容。帮助
$(document).ready(function(){
$(".test").click(function(event) {
setTimeout($(".frame").load(this.href),5000) ;
});
});
当你说
setTimeout($(".frame").load(this.href),5000);
你是 运行 $(".frame").load(this.href)
,并将该表达式的 结果 传递给 setTimeout。
您应该将它放在匿名函数中,这涉及缓存 this 变量(正如@hindmost 所指出的):
var self = this;
setTimeout(function() {
$(".frame").load(self.href);
},5000) ;
我需要在单击按钮 2 秒后加载 div 的内容。内容是其他 html 文件。当我使用
setTimeout($(".frame").load(this.href),5000);
div 立即加载文件内容。帮助
$(document).ready(function(){
$(".test").click(function(event) {
setTimeout($(".frame").load(this.href),5000) ;
});
});
当你说
setTimeout($(".frame").load(this.href),5000);
你是 运行 $(".frame").load(this.href)
,并将该表达式的 结果 传递给 setTimeout。
您应该将它放在匿名函数中,这涉及缓存 this 变量(正如@hindmost 所指出的):
var self = this;
setTimeout(function() {
$(".frame").load(self.href);
},5000) ;