<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>送给我们亲爱的____老师title>
<embed src="Meeting.mp3" hidden="true" autostart="true" loop="true">
head>
<style >
div{
margin-left: 60px;
margin-top: 70px;
margin-right: 60px;
margin-bottom: 50px;
width: 1250px;
height: 100px;
border:1px
solid #FFFFFF00;
font-size: 40px;
font-family: "Comic Sans MS";
color: #000000;
}
style>
<body>
<body background="Background.jpg"
style="background-repeat: no-repeat;
background-size: 100%;
background-attachment: fixed;">
<div id = "test">div>
<script >
//用#代替换行,用$代替空格
var text = "Dear Mrs.Ma,# $ $ I'm sorry to hear that you won't teach us next term. But the memory between you and us has already deepen in my mind. # $ $ In the early lessons you taught us, I thought you are a classy teacher. A few weeks later, I found you are also a skillful teacher. Your teaching methods are so extraordinary that I have made a wonderful progress just less than one year. It's responsible to you for correcting our writing practice homework and writing down your advice on everyone's paper. Besides, you are a rich idea teacher. The punishment that let the lazy students perform in front of the whole class is excellent! You are our friend more than our teacher. When we play a joke on your Chinese pronunciation, you'll blame us with smile. When you called yourself “microphone master”, we thought “What a cute teacher you are!” # $ $ I'll continue to study hard in English and live up to your expectations. Hope you can get along well with your new students. Please don't forget us! Love you!# $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ Your sincere students. ";
var context="";
var num = text.length;
var i =0;
function show() {
if(text[i] == "#"){
context += "
";
}else if(text[i] == "$"){
context += " ";
}else{
context += text[i];
}
document.getElementById("test").innerHTML = context;
i++;
if(i + 1 >= num){
clearInterval("done");
}
}
var done=setInterval("show()",10);
script>
body>
html>
clearInterval(done);
clearInterval()函数括号里的done不用加引号吧?可以查一下JS文档,此处应该是不用加的。
附:
clearInterval() 方法可取消由 setInterval() 函数设定的定时执行操作。
clearInterval() 方法的参数必须是由 setInterval() 返回的 ID 值。
done是变量,不要加引号
clearInterval(done); //去掉引号
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>送给我们亲爱的____老师</title>
<embed src="Meeting.mp3" hidden="true" autostart="true" loop="true">
</head>
<style >
div{
margin-left: 60px;
margin-top: 70px;
margin-right: 60px;
margin-bottom: 50px;
width: 1250px;
height: 100px;
border:1px
solid #FFFFFF00;
font-size: 40px;
font-family: "Comic Sans MS";
color: #000000;
}
</style>
<body>
<body background="Background.jpg"
style="background-repeat: no-repeat;
background-size: 100%;
background-attachment: fixed;">
<div id="test"></div>
<script>
//用#代替换行,用$代替空格
var text = "Dear Mrs.Ma,# $ $ I'm sorry to hear that you won't teach us next term. But the memory between you and us has already deepen in my mind. # $ $ In the early lessons you taught us, I thought you are a classy teacher. A few weeks later, I found you are also a skillful teacher. Your teaching methods are so extraordinary that I have made a wonderful progress just less than one year. It's responsible to you for correcting our writing practice homework and writing down your advice on everyone's paper. Besides, you are a rich idea teacher. The punishment that let the lazy students perform in front of the whole class is excellent! You are our friend more than our teacher. When we play a joke on your Chinese pronunciation, you'll blame us with smile. When you called yourself “microphone master”, we thought “What a cute teacher you are!” # $ $ I'll continue to study hard in English and live up to your expectations. Hope you can get along well with your new students. Please don't forget us! Love you!# $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ Your sincere students. ";
var context="";
var num = text.length;
var i =0;
function show() {
if(text[i] == "#"){
context += "<br>";
}else if(text[i] == "$"){
context += " ";
}else{
context += text[i];
}
document.getElementById("test").innerHTML = context;
i++;
if(i + 1 >= num){
clearInterval(done); //去掉引号
}
}
var done=setInterval("show()",10);
</script>
</body>
</html>
如有帮助,请点击我的回答下方的【采纳该答案】按钮帮忙采纳下,谢谢!
需要改两处
1、done是定时器id指向etInterval(show,10)的返回值,是引用,不应该加“”,加引号就成为字符串了
2、定时器第一项参数应该是function类型的变量,不应该加“show()”,这样也成了字符串,应该为show
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>送给我们亲爱的____老师</title>
<embed src="Meeting.mp3" hidden="true" autostart="true" loop="true">
</head>
<style >
div{
margin-left: 60px;
margin-top: 70px;
margin-right: 60px;
margin-bottom: 50px;
width: 1250px;
height: 100px;
border:1px
solid #FFFFFF00;
font-size: 40px;
font-family: "Comic Sans MS";
color: #000000;
}
</style>
<body>
<body background="Background.jpg"
style="background-repeat: no-repeat;
background-size: 100%;
background-attachment: fixed;">
<div id="test"></div>
<script>
//用#代替换行,用$代替空格
var text = "Dear Mrs.Ma,# $ $ I'm sorry to hear that you won't teach us next term. But the memory between you and us has already deepen in my mind. # $ $ In the early lessons you taught us, I thought you are a classy teacher. A few weeks later, I found you are also a skillful teacher. Your teaching methods are so extraordinary that I have made a wonderful progress just less than one year. It's responsible to you for correcting our writing practice homework and writing down your advice on everyone's paper. Besides, you are a rich idea teacher. The punishment that let the lazy students perform in front of the whole class is excellent! You are our friend more than our teacher. When we play a joke on your Chinese pronunciation, you'll blame us with smile. When you called yourself “microphone master”, we thought “What a cute teacher you are!” # $ $ I'll continue to study hard in English and live up to your expectations. Hope you can get along well with your new students. Please don't forget us! Love you!# $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ Your sincere students. ";
var context="";
var num = text.length;
var i =0;
function show() {
if(text[i] == "#"){
context += "<br>";
}else if(text[i] == "$"){
context += " ";
}else{
context += text[i];
}
document.getElementById("test").innerHTML = context;
i++;
if(i + 1 >= num){
clearInterval(done); //done是定时器id指向etInterval("show()",10)的返回值,是引用,不应该加“”,加引号就成为字符串了
}
}
var done=setInterval(show,10);//定时器第一项参数应该是function类型的变量,不应该加“show()”,这样也成了字符串
</script>
</body>
</html>
您的采纳就是对我最大的动力,谢谢!!!
function show() {
if(text[i] == "#"){
context += "
";
}else if(text[i] == "$"){
context += " ";
}else{
context += text[i];
}
document.getElementById("test").innerHTML = context;
i++;
if(i + 1 >= num){
clearInterval(done);
}
}
var done=setInterval(show(),10);