Sim*_*mon 1 javascript jquery settimeout
我尝试在更改窗口位置时丰富闪存效果,但是有一个小问题,我无法解决.
请看一下剧本
$(document).ready(function(){
$('a.flash').click(function(e) {
e.preventDefault();
$('body').fadeOut(1500);
setTimeout("", 1500);
window.location=this.href;
});
});
Run Code Online (Sandbox Code Playgroud)
window.location=this.href必须在1500ms后完成,但不会发生.你能解释一下原因吗?有什么奇怪的,当我尝试写alert("something");而不是window.location=this.href,它工作正常.你能解释一下原因吗?
谢谢
$(document).ready(function(){
$('a.flash').click(function(e) {
var el = this;
e.preventDefault();
$('body').fadeOut(1500);
setTimeout( function() { location=el.href }, 1500 );
});
});
Run Code Online (Sandbox Code Playgroud)
你应该提供一个回调函数作为setTimeout的第一个参数,它在1500毫秒后被调用.
| 归档时间: |
|
| 查看次数: |
5632 次 |
| 最近记录: |