Javascript 如何使用;设置超时“;在jQuery中?
我有以下代码:Javascript 如何使用;设置超时“;在jQuery中?,javascript,jquery,html,Javascript,Jquery,Html,我有以下代码: <head> <script> $(document).ready(function() { window.setTimeout(function() { $("#Error").animate({margin:"-50px"}); $("#errorCloseholder").animate({margin:"-50px"}); }, 2000); }); </scri
<head>
<script>
$(document).ready(function() {
window.setTimeout(function() {
$("#Error").animate({margin:"-50px"});
$("#errorCloseholder").animate({margin:"-50px"});
}, 2000);
});
</script>
</head>
$(文档).ready(函数(){
setTimeout(函数(){
$(“#错误”).animate({margin:-50px});
$(“#errorCloseholder”).animate({margin:-50px});
}, 2000);
});
这段代码在jQuery的帮助下,应该在2秒钟后隐藏一些元素
不幸的是,这段代码不起作用。这与jQuery有关吗?还是我有某种语法错误
这些元素的id为Error和errorCloseholder,它们都是在2秒后隐藏的错误消息
提前谢谢
$(document).ready(function () {
setTimeout(function(){
$("#Error").animate({margin: "-50px"});
$("#errorCloseholder").animate({margin: "-50px"});
}, 2000);
});
删除“;”来自脚本。您的
.ready()
函数末尾出现语法错误
};); //this one remove the first semi colon
</script>
</head>
};)//这一个去掉了第一个分号
尝试在此处使用.load()
事件
$(document).ready(function() {
$(window).load(function(){
setTimeout(function(){
$("#Error").animate({margin:"-50px"});
$("#errorCloseholder").animate({margin:"-50px"});
}, 2000);
});
});
看起来你的分号太多了。尝试删除“.ready”函数中倒数第二个函数,看看是否有帮助。您可以使用
setTimeout()
方法在定义的毫秒数后调用函数
$(document).ready(function () {
var x = document.getElementById("txt");
setTimeout(function(){x.value="2 seconds"},2000);<br/>
setTimeout(function(){x.value="4 seconds"},4000);<br/>
setTimeout(function(){x.value="6 seconds"},6000);<br/>
}
$(文档).ready(函数(){
var x=document.getElementById(“txt”);
setTimeout(function(){x.value=“2秒”},2000);
setTimeout(function(){x.value=“4秒”},4000);
setTimeout(function(){x.value=“6秒”},6000);
}
这里,“txt”是标签或文本框。
结果如下:2秒
4秒
6秒从这个
};)开始
^哈哈,这是注释
只需按键盘上1左边的“那个按钮”。您不需要窗口。
前缀在这里;出于好奇,我提到了这一点:为什么在这里使用超时,而不是带有转换延迟的CSS类?请投票关闭typo@kuma键盘地图可以根据你离开哪个国家而定我找到了:Azerty键盘->altgr+7+空格
法语口音``问题在眨眼间------>;)如何在注释中添加代码标记?^哈哈,这是注释
只需按键盘上1左边的“那个按钮”。什么->$(文档)。准备好(函数(){$(窗口)。加载(函数(){为什么?我以为在加载资源之前会完成动画。所以用户看不到它。$(文档)。准备好(//还不够吗?