2015-11-01 40 views
-1

所以我希望能够在对象和目标文本栏中输入任何值来显示结果。但是,我的重置按钮有效,但“处理”按钮不起作用。显然这个函数没有被调用,但我不知道为什么这个函数没有被调用。Javascript:代码不起作用,但没有错误

<html> 


<head> 
    <script LANGUAGE="JavaScript"> 
    <!-- hide script from uneducated browsers 
     function newVerse(form) 
     { 
      obect = form.object.value 
      destination = form.destination.value 
      var result 
      result = "Where have all the " + object + " gone?<br />"+ "Long time passing.<br />"+ "Where have all the " + object + " gone? <br />"+ "Long time ago.<br />"+ "Where have all the " + object + " gone?.<br />" + "Gone to " + destination + " everyone.<br />"+ 
      "When will they ever learn?<br />"+ "When will they ever learn?<br />" 
      return result 
     } 
     // end script hiding from uneducated browsers --> 
    </script> 
</head> 

<body> 
<form> 
    <b>Object</b>: <input TYPE="text" NAME="object" ID="objectID" /> 
    <p> 
    <b>Destination</b>: <input Type="text" Name="destination" ID="destinationID" /> 
    </p><p> 
    <textarea TYPE="textarea" NAME="text" ID="textID" rows="1" cols="50" /> </textarea> 
    <p> 
    <input TYPE="Reset"/> 
    <input TYPE="button" VALUE="Process" onClick="newVerse(this.form)" 

    </p><p> 
</form> 


<i>(lyrics by Pete Seeger)</i> 
<hr /> 
</body> 
</html> 
+0

我有问题,添加代码块,这是使用本网站我的第一次。不便之处 –

+0

没有错误?它会抛出“ReferenceError:object is not defined”。 (打开控制台选项卡查看错误消息。) – JJJ

+0

检查您的控制台日志 - 它正在抛出错误,您应该阅读它们以帮助您排除故障。 – Terry

回答

0

没有为你分配一个变种,以obectobject一个错字。你也缺少一些var s(并且使你的变量成为全局变量,这是一种不好的做法)。

我建议如下:

function newVerse(form) 
    { 
     var object = form.object.value 
     var destination = form.destination.value 
     var result = "Where have all the " + object + " gone?<br />"+ "Long time passing.<br />"+ "Where have all the " + object + " gone? <br />"+ "Long time ago.<br />"+ "Where have all the " + object + " gone?.<br />" + "Gone to " + destination + " everyone.<br />"+ 
     "When will they ever learn?<br />"+ "When will they ever learn?<br />" 
     return result 
    } 
相关问题