身体标签可以保持两个设定的间隔吗?或者有2个函数使用相同的间隔?
例如:
<body onload="setInterval(function1, 500); setInterval(function2, 1000);">
<body onload="setInterval(function1, function2, 500");>
Run Code Online (Sandbox Code Playgroud) 代码:
setInterval("doSomething()", 2000);
function doSomething(){alert('hi')}
Run Code Online (Sandbox Code Playgroud)
我一直在读这个,我只是无法得到这个例子:(
使用setInterval/setTimeout,如何确保我的函数FINISH在等待一段时间后再执行,然后再执行,然后等待,等等.谢谢.
我想在JQueryMobile页面中显示加载动画微调器,该页面加载了a/ajax off.
页面加载data-ajax="false"或rel="external"
我试着pagebeforecreate和pageshow事件,但它不工作如我所料:
$( '#page' ).live( 'pagebeforecreate',function(event){
$.mobile.loading('show');
});
$( '#page' ).live( 'pageshow',function(event){
$.mobile.loading('hide');
});
Run Code Online (Sandbox Code Playgroud) setinterval jquery-mobile clearinterval jquery-mobile-loader
在html中我提到了一个id ="txt"的类
<p id="txt">1</p>
Run Code Online (Sandbox Code Playgroud)
我需要每500毫秒间隔加1.我使用了以下代码,但它没有用.
function timedText() {
var x = document.getElementById('txt');
setInterval(function () {x= "(parseInt(x, 10)+ 1).toString(10)";},500);
}
Run Code Online (Sandbox Code Playgroud)
单击按钮时会调用上述功能.
总而言之,我正在尝试使用随机报价生成器.我的代码非常简单......
var myQuotes = [
{
quote: "To err is human; to forgive, divine.",
cite: "Alexander Pope"},
{
quote: "Reports of my death have been greatly exaggerated.",
cite: "Mark Twain"}
];
var randomQuote = Math.floor(Math.random() * myQuotes.length);
$('.quote').html(myQuotes[randomQuote].quote); // #1
$('.cite').html(myQuotes[randomQuote].cite);
setInterval(function() {
$('.quote').fadeOut();
$('.quote').fadeIn().html(myQuotes[randomQuote].quote); // #2
}, 3000);
Run Code Online (Sandbox Code Playgroud)
在加载时,它显示#1就好了,但#2似乎不起作用......它只是保持闪烁与之前相同的一个,#1中的那个.我对此不了解什么?
我想要做的是设置每个BannerImg元素显示:使用计时器设置一次一个.然后,一旦我循环遍历所有BannerImg元素,我想重置它们以显示:block.它基本上就像我想要制作的图像旋转器......但是现在,我不确定如何一次一个地定位每个BannerImg元素 - 我一次瞄准它们,这不是我的意思想做.
jQuery.noConflict();
(function($) {
$(document).ready(function() {
var BannerCount = $('BannerImg').length;
var intervalID = window.setInterval(function() {
$('.BannerImg').toggleClass("HideBannerImg");
}, 2000);
});
}(jQuery));
Run Code Online (Sandbox Code Playgroud) 这是我的代码:
<script type="text/javascript">
<!--
window.onload = function() {
function obtenirTOC(){
$.ajax({
type: "post",
url: "http://saaprod/soutien_tache/outils/preferencesAO/tocCheck.asp",
success: function(str){
if (str=="Oui"){
$("#show-hide-navigation").click();
}
}
})
}
setInterval(obtenirTOC(),30000);
}
//-->
</script>
Run Code Online (Sandbox Code Playgroud)
我的代码没有像预期的那样等待30000毫秒。只要加载页面,它就会开始运行。
你能帮助我吗?
谢谢!
以下代码:
<script type="text/javascript">
function a() {
document.write("bob ");
}
setInterval("a()", 1000);
</script>
Run Code Online (Sandbox Code Playgroud)
是应该有一个出放1 bob,printed在浏览器上,every second.
我正在使用firefox,它只打印onces,没什么......任何人有任何想法为什么?mauybe我错过了什么?ec = now.getSeconds(); document.write(hours +':'+ mins +':'+ sec +"
"); }
UPDATE EDIT:
Run Code Online (Sandbox Code Playgroud)
我对此代码有同样的问题:
<script type="text/javascript">
function printtime () {
var now = new Date();
var hours = now.getHours();
var mins = now.getMinutes();
var sec = now.getSeconds();
document.write(hours+':'+mins+':'+sec+"<br />");
}
setInterval("printtime()", 1000);
</script>
Run Code Online (Sandbox Code Playgroud)
它应该打印在前一个浏览器上的时间,每秒一次....但它不会比第一个打印更多..
我似乎在我的代码中找不到setinterval()的正确用法。它应该每秒刷新9种新的随机颜色。
我已经尝试将代码放置在带有嵌套循环的箭头函数中,希望这将为完成的每个循环启动间隔。
但是,这并没有解决任何问题。请参考下面的完整代码:
let test = () => {
for (let i = 0; i <= 9; i++) {
addRandomColorToSquare();
}
}
setInterval(test, 1000);
let addSquareToDOM = function(color) {
let square = document.createElement('div');
square.className = 'square';
square.style.backgroundColor = color;
document.body.appendChild(square);
}
let addRandomColorToSquare = function() {
const randomRed = Math.floor(Math.random() * 256);
const randomGreen = Math.floor(Math.random() * 256);
const randomBlue = Math.floor(Math.random() * 256);
let rgbColor = `rgb(${randomRed}, ${randomGreen}, ${randomBlue})`;
addSquareToDOM(rgbColor);
test();
}Run Code Online (Sandbox Code Playgroud)
setinterval ×10
javascript ×9
jquery ×2
delay ×1
function ×1
html ×1
onload ×1
parseint ×1
settimeout ×1
timer ×1