繁体   English   中英

JavaScript无法在HTML中执行文本框值

[英]JavaScript not executing text-box value in HTML

我不熟悉HTML中的JavaScript,并获得了使用JS编写Mad Lib表单的项目。 我对其进行了编码并对其进行了多次审查,但我找不到该代码的问题:该程序未更改HTML文档中的文本框值。 你能帮忙吗? 码:

 function madLib() { var name, object, objectTwo, adjective, adverb, verb, place, mood, buildingStructure; name = document.MadLibForm.name.value; object = document.MadLibForm.object.value; objectTwo = document.MadLibForm.objectwo.value; adjective = document.MadLibForm.adjective.value; adverb = document.MadLibForm.adverb.value; verb = document.MadLibForm.verb.value; place = document.MadLibForm.place.value; mood = document.MadLibForm.mood.value; buildingStructure = name + " went to PLACE after a long time. " + name + " loved " + place + " because it was his/her favorite place when she was a kid. " + name + " took the " + adjective + " " + obeject + " with him to the " + place + ", which he/she used to it " + adverb + verb + ". He/She also took " + objectTwo + " with him/her, but did not use it at all during the visit. Still, at the end of the visit, he/she was very " + mood + " ."; document.MadLibForm.displayFullMadLib.value = buildingStructure; } 
 <!DOCTYPE html> <head> <title>Mad Libs</title> <meta charset="utf-8"> <link rel="stylesheet" href="styles.css" type="text/css"> <script> function madLib() { var name, object, objectTwo, adjective, adverb, verb, place, mood, buildingStructure; name = document.MadLibForm.name.value; object = document.MadLibForm.object.value; objectTwo = document.MadLibForm.objectwo.value; adjective = document.MadLibForm.adjective.value; adverb = document.MadLibForm.adverb.value; verb = document.MadLibForm.verb.value; place = document.MadLibForm.place.value; mood = document.MadLibForm.mood.value; buildingStructure = name + " went to PLACE after a long time. " + name + " loved " + place + " because it was his/her favorite place when she was a kid. " + name + " took the " + adjective + " " + obeject + " with him to the " + place + ", which he/she used to it " + adverb + verb + ". He/She also took " + objectTwo + " with him/her, but did not use it at all during the visit. Still, at the end of the visit, he/she was very " + mood + " ."; document.MadLibForm.displayFullMadLib.value = buildingStructure; } </script> </head> <body> <div id="main"> <form name="MadLibForm"> <table> <tr> <th colspan="2">wEiRd Mad Lib</th> </tr> <tr> <td>Your Name</td> <td> <input type="text" name="name" class="inputs"> </td> </tr> <tr> <td>Object</td> <td> <input type="text" name="object" class="inputs"> </td> </tr> <tr> <td>Another Object</td> <td> <input type="text" name="objecttwo" class="inputs"> </td> </tr> <tr> <td>Place</td> <td> <input type="text" name="place" class="inputs"> </td> </tr> <tr> <td>Verb</td> <td> <input type="text" name="verb" class="inputs"> </td> </tr> <tr> <td>Adjective</td> <td> <input type="text" name="adjective" class="inputs"> </td> </tr> <tr> <td>Adverb</td> <td> <input type="text" name="adverb" class="inputs"> </td> </tr> <tr> <td>Mood</td> <td> <input type="text" name="mood" class="inputs"> </td> </tr> <tr> <td> <div> <input type="button" onClick="madLib()" value="Get Your Story!" id="button"> </div> </td> </tr> <tr> <td colspan="2">&nbsp; <textarea name="displayFullMadLib" rows="9" cols="65"></textarea> </td> </tr> </table> </form> </div> <!--main--> </body> </html> 

非常感谢 :)

经过两次更改, 您更新的小提琴可以正常工作。

  1. 变更:

     objectTwo = document.MadLibForm.objectwo.value; 

    至 :

     objectTwo = document.MadLibForm.objecttwo.value; //two `t` 
  2. 更换obejectobject中:

     ..." took the " + adjective + " " + object + " with him to the " + place ...+ 

JS:

madLib = function() {
      var name, object, objectTwo, adjective, adverb, verb, place, mood, buildingStructure;
      name = document.MadLibForm.name.value;
      object = document.MadLibForm.object.value;
      objectTwo = document.MadLibForm.objecttwo.value;
      adjective = document.MadLibForm.adjective.value;
      adverb = document.MadLibForm.adverb.value;
      verb = document.MadLibForm.verb.value;
      place = document.MadLibForm.place.value;
      mood = document.MadLibForm.mood.value;

      buildingStructure = name + " went to PLACE after a long time. " + name + " loved " + place + " because it was his/her favorite place when she was a kid. " + name + " took the " + adjective + " " + object + " with him to the " + place + ", which he/she used to it " + adverb + verb + ". He/She also took " + objectTwo + " with him/her, but did not use it at all during the visit. Still, at the end of the visit, he/she was very " + mood + " .";

      document.MadLibForm.displayFullMadLib.value = buildingStructure;
}

错字:

objectTwo = document.MadLibForm.objectwo.value;

应该

objectTwo = document.MadLibForm.objecttwo.value;

注意两个“ t”。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM