clearinterval怎么读(JS的clearInterval()不起作用,应该怎么写才对)
本文目录
JS的clearInterval()不起作用,应该怎么写才对
《!DOCTYPE html》
《html》
《head》
《meta charset="utf-8"》
《title》setInterval《/title》
《/head》
《body》
《input type="text" id="aa" name="user_name" value="4"》
《input type="button" onclick="start()" value="开始"》
《div id="msg"》
《div》
《iframe id="one" src="" width="0" height="0" scrolling="no"》《/iframe》
《script type="text/javascript"》
***隐藏网址***
var a = 0;
var b = null;
var txt_obj = document.getElementById("aa");
function myrefresh()
{
a++;
if (a 》 parseInt(txt_obj.value)){
document.getElementById("msg").innerText ="已经完成"+a+"次,结束程序";
clearInterval(b);
txt_obj.value = 0;
}else{
//刷吧
document.getElementById("msg").innerText = a;
document.getElementById("one").src = one_id;
}
}
function start(){
//周期性执行myrefresh 函数
b = setInterval(myrefresh,1000);
}
《/script》
《/div》
《/body》
《/html》
你没有很好的理解setInterval的含义。
可以看下我的相关视频
***隐藏网址***
怎么用JavaScript写一个简单的小说阅读器
《html》
***隐藏网址***
《head》
《title》《/title》
《script type="text/javascript"》
function Reader(content, cID, stopID, continueID) {
this.conLoad = document.getElementById(cID);
this.stopBtn = document.getElementById(stopID);
this.continueBtn = document.getElementById(continueID);
this.content = content;
this.index = 0;
var t = this;
this.stopBtn.onclick = (
function () {
return function () {
t.stopReader(t);
};
})(t);
this.continueBtn.onclick = (
function () {
return function () {
t.continueReader(t);
};
})(t);
}
Reader.prototype = {
startReader : function () {
var t = this;
t.toId = setInterval(function () {
if (t.content) {
t.conLoad.innerHTML += t.content;
}
t.index++;
if (t.content.length == t.index) {
clearInterval(t.toId);
t.conLoad.innerHTML += "【未完待续】";
}
}, 200);
},
stopReader : function (t) {
t.flag = true;
clearInterval(t.toId);
},
continueReader : function (t) {
if (t.flag)
t.startReader();
t.flag = false;
}
};
var content = "蒙古亲王僧格林沁慓悍勇猛,他率领的军队向来号称能征惯战,八旗兵、绿营他都看不上眼,更何况那些临时招募的练勇。可偏偏就是这些他眼中的乌合之众,这些年来在江南战果累累,最终攻下了江宁,夺得了对太平军作战的全胜。" +
"相反地,他的蒙古铁骑在与捻军的角逐中常常打败仗,相形之下,昔日的声威锐减。这个一代天骄的后裔,对曾氏兄弟和湘军窝着一肚皮无名怒火。" +
"湘军进江宁后,打劫财富,屠城纵火,又放走幼天王,朝野谤讟四起,物议沸腾,僧格林沁听了十分得意,赶紧打发富明阿以视察满城为由,去江宁实地了解。谁料曾国荃一吓一贿征服了富明阿,江宁将军回去后向僧格林沁作了假汇报。";
//页面加载完成之后执行。
window.onload = function () {
new Reader(content, "content", "btnStop", "btnContinue").startReader();
};
《/script》
《body》
《div id=’content’》《/div》
《div id=’operate’》《input type=’button’ id=’btnStop’ value=’stop’/》《input type=’button’ id=’btnContinue’ value=’continue’/》《/div》
《/body》
《/html》
更多文章:
tran**issionfault是什么意思(tran**ission意思)
2026年4月15日 13:00
社区类网站源码(求好心人赏一个WordPress 网站 LightSNS社区源码完整版,授权真心买不起啊!)
2026年4月15日 12:20
雪铁龙service(雪铁龙世嘉service是什么故障灯)
2026年4月15日 12:00
clearinterval怎么读(JS的clearInterval()不起作用,应该怎么写才对)
2026年4月15日 11:00
js点击按钮弹出文本框(用PHP和JS怎么实现鼠标点击“评论”两个字之后在下面弹出文本框,就是类似QQ空间心情评论那种,在线等)
2026年4月15日 10:20
素数c语言程序编写100以内(输出100以内的质数,用c语言编写)
2026年4月15日 10:00





