Javascript 如何在一段时间后加载div内容。SetTimeout(),Load()
我需要加载的div内容,2秒后点击按钮。内容是其他html文件。当我使用Javascript 如何在一段时间后加载div内容。SetTimeout(),Load(),javascript,jquery,load,Javascript,Jquery,Load,我需要加载的div内容,2秒后点击按钮。内容是其他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);
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
您应该将它放在一个匿名函数中,这涉及到缓存这个变量(正如@hindmost所指出的):
此
将丢失匿名函数中的上下文。因此,您必须将其存储在单独的变量中。非常感谢!工作我真是疯了;(
var self = this;
setTimeout(function() {
$(".frame").load(self.href);
},5000) ;