Javascript ASCII动画

Javascript ASCII动画,javascript,html,Javascript,Html,我不确定我的代码中缺少了什么。我不能让我的空闲时间去工作。。。我一直收到一个错误,说myStopFunction()未定义。有什么想法吗? 我试着重新命名它,并检查以确保所有匹配,我只是不知道为什么我一直得到这个该死的错误 <!doctype html> <html> <head> <meta charset="utf-8"> <title>ASCII Animations</title> <h1> ASCII

我不确定我的代码中缺少了什么。我不能让我的空闲时间去工作。。。我一直收到一个错误,说myStopFunction()未定义。有什么想法吗? 我试着重新命名它,并检查以确保所有匹配,我只是不知道为什么我一直得到这个该死的错误

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>ASCII Animations</title>
<h1> ASCII Animation Editor/Viewer </h1>
<br><h3> Jordan Keith: Linn-Benton Community College</h3>
<body>
<p> Enter the frams below, separated by "=====" 
<input onclick = "playAnimation();" type="button" id= "Play" value = "PLAY" />
<input onclick = "myStopFunction();" type="button" id= "Stop" value = "STOP" /></p>
<textarea id = "frameArea" cols="50" rows="30"></textarea>

<textarea id = "displayArea" cols="50" rows="30"></textarea>

<script src="ASCII.js"></script><br>

</form>
</div> 
</body>
</html>

您对myStopFunction的调用缺少C in函数

clearInterval(t); 

是用于清除Javascript的计时器的内容

myStopFunction
由于函数名输入错误而未被调用

函数myStopFunction()
替换为
函数myStopFunction()

以下是运行代码:

<head>
<script>
function playAnimation() 
{
    frameStr = document.getElementById("frameArea").value;

    if (frameStr.indexOf("\r\n") != -1) {
        frameSeq = frameStr.split("=====\r\n");
    } else {
        frameSeq = frameStr.split("=====\n");
    }

    currentFrame = 0;
    showNextFrame();
}
var t;

function showNextFrame() 
{
    document.getElementById("displayArea").value = frameSeq[currentFrame];

    currentFrame = (currentFrame + 1) % frameSeq.length;

    t = setTimeout(showNextFrame, 250);

}

function myStopFunction() 
{
    alert("Stopping Now");
    clearTimeout(t);
}
</script>
</head>
<body>
<form>
    <input onclick="playAnimation();" type="button" id="Play" value="PLAY" />
    <input onclick="myStopFunction();" type="button" id="Stop" value="STOP" />
    <textarea id="frameArea" cols="50" rows="30"></textarea>
    <textarea id="displayArea" cols="50" rows="30"></textarea>
</form>
</body>

函数playAnimation()
{
frameStr=document.getElementById(“frameArea”).value;
if(frameStr.indexOf(“\r\n”)!=-1){
frameSeq=frameStr.split(===\r\n”);
}否则{
frameSeq=frameStr.split(===\n”);
}
currentFrame=0;
showNextFrame();
}
变量t;
函数showNextFrame()
{
document.getElementById(“displayArea”).value=frameSeq[currentFrame];
currentFrame=(currentFrame+1)%frameSeq.length;
t=设置超时(showNextFrame,250);
}
函数myStopFunction()
{
警惕(“立即停止”);
清除超时(t);
}

JSFIDDLE链接

您的javascript说的是
函数myStopFuntion()
。这里缺少了一个c。myStopFunction()没有定义-有时(我知道这在计算世界中很少见!)这是最简单的解释;-)
<head>
<script>
function playAnimation() 
{
    frameStr = document.getElementById("frameArea").value;

    if (frameStr.indexOf("\r\n") != -1) {
        frameSeq = frameStr.split("=====\r\n");
    } else {
        frameSeq = frameStr.split("=====\n");
    }

    currentFrame = 0;
    showNextFrame();
}
var t;

function showNextFrame() 
{
    document.getElementById("displayArea").value = frameSeq[currentFrame];

    currentFrame = (currentFrame + 1) % frameSeq.length;

    t = setTimeout(showNextFrame, 250);

}

function myStopFunction() 
{
    alert("Stopping Now");
    clearTimeout(t);
}
</script>
</head>
<body>
<form>
    <input onclick="playAnimation();" type="button" id="Play" value="PLAY" />
    <input onclick="myStopFunction();" type="button" id="Stop" value="STOP" />
    <textarea id="frameArea" cols="50" rows="30"></textarea>
    <textarea id="displayArea" cols="50" rows="30"></textarea>
</form>
</body>