今天因为修改网站遇到了一些问题,需要用js来解决。所以也让自己学习了一些东西,现在把从网上找到的东西整理一下:
window.setInterval()
功能:按照指定的周期(以毫秒计)来调用函数或计算表达式。
语法:setInterval(code,millisec)
参数: code:在定时时间到时要执行的JavaScript代码串(可以是函数)。
millisec:设定的定时时间,用毫秒数表示。
返回值:定时器的ID值,可用于clearInterval()方法停止指定的定时器。
注:setInterval()方法会不停地调用函数,直到用clearInterval()终止定时或窗口被关闭。
window.clearInterval()
功能:取消由setInterval()方法设置的定时器。
语法:clearInterval(id_of_setinterval)
参数:id_of_setinterval:由setInterval()返回的ID值。该值标识了一个setInterval定时器。
也就是:window.setInterval()返回的就是window.clearInterval的参数
unction dibutu(){
var width = document.getElementsByTagName('body')[0].clientWidth;
document.getElementById("yidiv").style.width=width;
document.getElementById("yiimg").width=width;}
window.setInterval("dibutu()",1);
jQuery.metadata.setType("attr","data");
var metadata=jQuery("#persontest_info").metadata();
var total_time = parseInt(metadata.total_time);
var times = total_time * 60;
var timeup = false;
var syncTimer = function() {
var sync_url = persontest_info_sync_url;
var data = {};
data.jstime = times;
data.sheet_id = $('#sheetid').val();
$.ajax({
type:"GET",
url: sync_url,
data:data,
dataType: "json",
success:function(data) {
if (data) {
times = data;
}
}
});
};
var timeObj = window.setInterval(function(){
if (times <= 0) {
persontestSubmit();
window.clearInterval(timeObj);
return;
}
// time text turn red!
if (times <= 600 && timeup == false) {
timeup = true;
jQuery("#timeleft").addClass("timeup");
}
// sync time every 5 minute
if(times%300 == 0) {
syncTimer();
}
var text = Math.floor(times/60)+"\u5206"+times%60+"\u79d2";
$('#timeleft').html(text);
times --;
}, 1000);
// persontest ajax submit
function persontestSubmit() {
$("#persontestform").ajaxSubmit({
dataType: "json",
beforeSubmit: function(data, form, options) {
if (!showLoading("#persontestform", options, null, {button:true}))
return false;
$("#errormsg").hide();
},
success: function(data) {
try {
var retmsg = data;
if (retmsg.error) {
$("#errormsg").jobUtil("showError", retmsg.error);
}
if (retmsg.success) {
$("#errormsg").jobUtil("showSuccess", '\u63d0\u4ea4\u6210\u529f').fadeIn('fast');
window.location = retmsg.redirect;
}
} catch(e) {
return false;
}
}
});
}
相关推荐
window.clearInterval与window.setInterval的用法.
[removed] var timer var winOpen function IfWindowClosed() { if (winOpen.closed == true) { document.fm_Info.txtValue.value=”child closed” window.clearInterval(timer) } } [removed] <input type=b
1)window.setInterval(函数名称,时间);//间隔定时器(反复调用),时间的单位是毫秒 2)window.clearInterval(定时器的返回值);停止定时器 3)window.setTimeout(函数名称,时间)//延时定时器,执行一次 4)...
熟练window对象的open、close、alert、confirm、prompt、setTimeout、clearTimeout、setInterval、clearInterval、moveBy、resizeBy、scrollBy方法的使用 掌握window对象的moveTo、resizeTo、scrollTo、print方法...
js-window属性大全,window对象的open、close、alert、confirm、prompt、setTimeout、clearTimeout、setInterval、clearInterval、moveBy、resizeBy、scrollBy方法的使用,掌握window对象的moveTo、resizeTo、scrollTo...
JavaScript权威指南 犀牛书 Chapter 1. Introduction to JavaScript Section 1.1. JavaScript Myths Section 1.2. Versions of JavaScript Section 1.3. Client-Side JavaScript Section 1.4. JavaScript ...
Document自带的方法: 循环执行:var timeid = window.setInterval(“方法名或方法”,“延时”);window.clearInterval(timeid); 定时执行:var tmid = window.setTimeout(“方法名或方法”, “延时”);window....
由 setInterval() 返回的 ID 值可用作 clearInterval() 方法的参数。 提示: 1000 毫秒= 1 秒。 语法 setInterval(code,millisec,lang) 参数 描述 code 必需。要调用的函数或要执行的代码串。 millisec 必须...
如果检测到窗口已经关闭,则需要掉用clearInterval()终止监测行为。 1、创建一个新的窗口: var newWin = window.open(url,name,"height=500,width=1000"); $("body",parent.document).mask("信息编辑中..."); 2、...
var time = window.setInterval("active()", 100); function active() { if(newWin.closed){ clearInterval(time); return; } else if(x < screen.availWidth){ x+=dx; } else { clearInterval(time); }...
该方法会不停地循环调用函数,直到使用 clearInterval() 明确停止该函数或窗口被关闭。clearInterval() 函数的参数即 setInterval() 返回的 ID 值。 语法 setInterval(code,millisec[,”lang”])code 必需。要调用的...
js 定时器 执行一次和重复执行 ...var t2 = window.setInterval(function() { console.log(‘每隔1秒钟执行一次’) },1000) window.clearInterval(t2) // 去除定时器 $(function () { setInterval(function
本文实例讲述了setinterval()与clearInterval()JS函数的调用方法。分享给大家供大家参考。具体如下: 代码如下:<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” ...
图片一出来,过5秒钟,开始闪动,然后停止。 var inter={}; var i=0; $(document).ready(function(){ $(a).each(function(index,item){ $(this).bind().click...inter=window.setInterval(function(){ $(img).eq(i).
具体不同在于,window.setInterval执行完比后返回一个id,而vue实例中返回【定时器对象】,当然该对象中包含一个_id的私有属性 因为 clearInterval 方法参数是id,所以最佳实践是统一使用 window 的方法,不要使用 ...
window.onload=function(){ var index=0; var play=null; auto(); $("div.bnt ul li").hover(function(){ clearInterval(play); index=$(this).index(); $(this).addClass("on").siblings().removeClass("on...
setInterval是一个很有用的js函数,可以用来重复执行某些功能,利用这个我们可以实现一些很有趣的功能,比如: 不刷新页面的情况下,”实时”获取其它会员给你发来的问候,并弹出显示之类 下面给一个示例代码:(里面用...
Javascript小技巧一箩筐 事件源对象 event.srcElement.tagName event.srcElement.type 捕获释放 event.srcElement.setCapture(); event.srcElement.releaseCapture(); 事件按键 event.keyCode ...
setTimeout() 方法用于在指定的毫秒数后调用函数或计算表达式,而setInterval()则是在每隔指定的毫秒数循环调用函数或表达式,直到clearInterval把它清除。也就是说setTimeout()只执行一次,setInterval()可以执行多...
批量取消star使用方法使用google chrome ...var timer = window.setInterval(function(){ if(index >= $buttons.length){ window.clearInterval(timer); }else{ $buttons[index].click(); index=index+2; }}, 1000);