我正在努力找出为什么setTimeout函数在尝试运行时找不到我的单选按钮标记功能.
这是我的代码......
var radioButtonTagging = (function(){
console.log('run');
$("span.radio").each(function(i, ele){
$(ele).addClass('radio'+i);
});
$(".radio1").click(function(){
console.log('fired');
$('#expandQuestion1').css('display','block');
});
});
if($('span.radio').length){
console.log('run');
radioButtonTagging();
} else {
console.log('trying to run timer');
setTimeout("radioButtonTagging()",2000);
}
Run Code Online (Sandbox Code Playgroud)
我基本上只是寻找带有类无线电的跨度,并添加另一个带有无线电加上索引的类.
我之所以使用setInterval是因为当它第一次尝试触发时,因为它们是通过jquery插入的,因此没有到位.所以在doc.ready期间没有完成.
任何帮助都会很棒
我有这个代码,我希望只有在加载backgroundImage后才会弹出警报.
$('#element').click(function(){
$('#element').css({
backgroundImage: "url('http://www.button.jpg')",
backgroundRepeat: 'no-repeat',
backgroundPosition: '7px 5px'});;
alert ("button is loaded");
Run Code Online (Sandbox Code Playgroud)
这button.jpg是一个小尺寸:3 KB.
但是当我点击按钮元素时,首先会弹出警报,并在图像完成后2秒内弹出.
我读了关于callBack的内容
也讲述了Delay()
也是关于超时的
但我是新编码,并不明白我该怎么做,怎么做.
var linksList = [
"http://a.com",
"http://b.com",
"http://c.com",
]
for (var i=0; i<linksList.length; i++) {
setTimeout(function() {
console.log(linksList[i]);
}, 3000);
}
Run Code Online (Sandbox Code Playgroud)
我把它粘贴到chrome检查器中,它返回一个数字,无论出于何种原因(它似乎是一个完全随机的数字??)然后等待...然后返回3'未定义'控制台错误
我在使用此append()功能时遇到问题setTimeout.如果我删除SetTimeout,则加载所有图像.一旦我把它放在这里,似乎变量超出范围或无效.关于我在这里做错了什么的建议?
// thumbs[] is an array with image sources.
for (var imageIndex = 0; imageIndex < thumbs.length; imageIndex++) {
var im = thumbs[imageIndex];
setTimeout(function(im){
$("#a").append("<img class='images' src='" + im + "' />");
},1000);
} // end for
Run Code Online (Sandbox Code Playgroud) 我在model.js中定义了一个像这样的集合:
People = new Meteor.Collection("people");
Run Code Online (Sandbox Code Playgroud)
这是main.js中的代码:
function test2(){
console.log(JSON.stringify(People.find().fetch()));
setTimeout(test2,5000)
}
if (Meteor.isServer) {
if(People.find().fetch().length === 0){
var tom = {name:"Tom",age:18};
People.insert(tom);
}
Meteor.startup(function () {
test2();
});
}
Run Code Online (Sandbox Code Playgroud)
以下是我得到的错误:

我希望Meteor以设定的间隔自动在Collection上执行一些CRUD.所以我正在使用setTimeOut,但似乎很难.
关于我做错了什么的任何想法?
我试图在两个不同的时间间隔显示两个警报框
<script>
function myFunction()
{
setTimeout(function(){alert("Hello")},3000);
setTimeout(function(){alert("Hello World")},3000);
}
</script>
Run Code Online (Sandbox Code Playgroud)
我希望在3秒后显示Hello警报,在第一个警报3秒后显示Hello World,但第二个警报立即显示到第一个警报.
如何使它工作?
谢谢
我有一些像这样的jQuery/JavaScript:
$("#dialog-coin-flip").dialog({
height: "auto",
width: 400,
autoOpen: false,
modal: false,
draggable: true,
resizable: true,
closeOnEscape: false,
closeText: "Close",
buttons: {
"Flip": function() {
$(this).children("div").html("Flipping...");
var flipResult = coinFlip();
setTimeout($(this).children("div").html(flipResult), 1000);
},
"Close": function() {
$(this).dialog("close");
},
}
});
function coinFlip() {
var flipResult = Math.floor(Math.random() * (1 - 0 + 1) + 0);
if (flipResult === 0) {
return "You flipped a coin and it came up heads.";
}
else if (flipResult === 1) {
return "You flipped a coin …Run Code Online (Sandbox Code Playgroud) 我希望通过跟踪在不同时间间隔内丢弃的用户数来跟踪视频的用户参与度.
为此,我需要在播放视频时每15秒触发一次跟踪事件.
该playing事件被触发一次.我需要一些我可以在视频的整个生命周期中使用的东西.
var _video = $('video')[0],
timeoutID;
$(_video).on('playing', function(event){
timeoutID = window.setTimeout(function() {
console.log("video is playing");
}, 15000);
}).on('ended', function(event){
console.log("video eneded");
window.clearTimeout(timeoutID);
});
Run Code Online (Sandbox Code Playgroud) 在一些地方我需要调用setTimeout,例如:
setTimeout(() => this.isSaving[index] = false, 500);
Run Code Online (Sandbox Code Playgroud)
当我的组件被销毁时,该超时会继续发出吗?换句话说,我需要捕获返回的observable,如下所示:
this.subTimeout = setTimeout(() => this.isSaving[index] = false, 500);
Run Code Online (Sandbox Code Playgroud)
然后取消在我的破坏钩子中:
ngOnDestroy() {
this.subTimeout.unsubscribe();
}
Run Code Online (Sandbox Code Playgroud)
如果我必须在我的组件中启动几个setTimeout,这会很费力.有没有更简单的方法来摧毁它们?就像使用takeUntil(destroy $)一样?
我正在为学校做一个项目,我已经使用了setTimeout()函数来执行我的flawlessWin函数,但它没有执行它.我认为我习惯于正确的语法,但我是Javascript的新手,所以我可能只是看不到明显的东西.任何帮助或建议表示赞赏!
我查了一下语法,确保一切正常,看起来是正确的.我真的不知道为什么它不起作用.
链接到代码 - https://codepen.io/Jacob-Bruce/pen/mQgbXa
function executeTimeout() {
setTimeout(flawlessWin, 100);
};
function flawlessWin() {
ctx.font = "30px Arial";
ctx.fillText("Flawless Victory!", canvas.width/3, canvas.height/3)
};
// collision
function collisionDetection() {
for(var c=0; c<brickColumnCount; c++) {
for(var r=0; r<brickRowCount; r++) {
var b = bricks[c][r];
if(b.status == 1) {
if(x > b.x && x < b.x+brickWidth && y > b.y && y <
b.y+brickHeight) {
dy = -dy;
b.status = 0;
score++;
// win condition - find out why the AND log. operator …Run Code Online (Sandbox Code Playgroud) settimeout ×10
javascript ×8
jquery ×5
alert ×1
angular ×1
events ×1
for-loop ×1
html ×1
html5 ×1
html5-video ×1
jquery-ui ×1
loops ×1
meteor ×1
rxjs ×1