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);
精彩评论