开发者

JavaScript - Show/Hide Without Refreshing Page

Can anyone help? I want to only show the script output if a particular application variable is true, without refreshing the page, as initially, the application variable could be false

&开发者_如何学Golt;body>
<div id="output"></div>
<script type="text/javascript">
var quotes = new Array(
'Quote 1',
'Quote 2',
'Quote 3'
);
function rotate() {
    quote = quotes.shift();
    quotes.push(quote);
    document.getElementById('output').innerHTML = quote;
    setTimeout("rotate()", 2000);
}
rotate();
</script>
</body>


You'll want to use setInterval instead of setTimeout. Something like this:

function showQuotes()
{
    if(someVariable)
    {
        quote = quotes.shift();
        quotes.push(quote);
        document.getElementById('output').innerHTML = quote;
    }
}
setInterval("showQuotes()",2000);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜