在javascript中执行回发之前延迟
Delay before doing postback in javascript
我现在唯一能想到的在3秒延迟的情况下进行回发的方法是这样的。
setInterval("__doPostBack('UpdatePanel1', '' )", 3000);
我遇到的问题是,它每3秒钟就会发一次回。有没有更好的方法来做到这一点,或者有没有一种方法来清除间隔?我使用的是asp更新面板控件。
以下是我的完整javascript代码,让您了解我正在尝试做的事情:
var delayb4scroll = 1000 //Specify initial delay before marquee starts to scroll on page (2000=2 seconds)
var marqueespeed = 2 //Specify marquee scroll speed (larger is faster 1-10)
var pauseAtBottom = 3000 //Pause at the end of the scroll for this many seconds (3000 = 3 seconds)
var copyspeed = marqueespeed
var actualheight = ''
var boolRunOnce = ''
function pageLoad() {
initializemarquee();
}
function scrollmarquee() {
if (parseInt(cross_marquee.style.top) - 975 > (actualheight * (-1) + 8)) //if scroller hasn't reached the end of its height
cross_marquee.style.top = parseInt(cross_marquee.style.top) - copyspeed + "px" //move scroller upwards
else { //else, scrollbar has reached the bottom, display for 3 seconds then postback
setInterval("__doPostBack('UpdatePanel1', '' )", 3000);
}
}
function initializemarquee() {
cross_marquee = document.getElementById("vmarquee")
cross_marquee.style.top = 0
marqueeheight = document.getElementById("marqueecontainer").offsetHeight
actualheight = cross_marquee.offsetHeight //height of marquee content (much of which is hidden from view)
setTimeout('lefttime=setInterval("scrollmarquee()",30)', delayb4scroll)
}
setTimeout(function() { __doPostBack('UpdatePanel1', '' ); }, 3000);
将只运行一次。
或者,您可以使用setInterval的返回值作为对间隔线程的引用,然后可以清除该线程;
myInterval = setInterval(function() { __doPostBack('UpdatePanel1', '' ); }, 3000);
//later
clearInterval(myInterval);
编辑:正确,根据注释添加函数语法。
相关文章:
- 如何延迟javascript函数的执行
- 延迟javascript以避免API限制
- 在非WebKit浏览器中延迟JavaScript执行
- 如何延迟 JavaScript 加载
- 延迟 JavaScript 函数执行
- 相对于GoogleMaps/geoxml3解析器延迟Javascript函数的执行
- 延迟javascript执行,直到DOM更改完成
- 延迟Javascript/Java中函数内的代码执行
- 如何延迟javascript的嵌入
- 延迟javascript DOM样式更改
- 如何延迟javascript onclick函数,使其不继续运行,除非在项目上完成单击
- 如何延迟javascript中特定函数的执行
- 延迟javascript函数,直到文件上传到asp页面之后
- 延迟Javascript解析给出错误
- 延迟Javascript中的ajax响应
- 用switch类延迟javascript动作
- 如何在while循环中添加延迟.JavaScript
- 延迟javascript在asp.net MVC中的加载
- 按下键延迟.Javascript
- 如何延迟JavaScript JSON流一分钟