-4

我真的很难运行解析按钮来显示输入框的结果......

这些是我的代码:

<html>
<head>
<title> sentence detector</title> </head>
<body background="english.jpg">
<font color="black">
<h1 align = center> TABLE OF WORDS </h1>
<br>
<h3>
<script>

var noun = new Array ("time", "year", "people", "way", "man", "day", "thing", "child", "Mr", "government", "work", "life", "woman", "system", "case", "part", "group", "number", "world", "house", "area", "company", "problem", "service", "place", "hand", "party", "school", "country", "point", "week", "member", "end", "state", "word", "family", "fact", "head", "month", "side", "business", "night", "eye", "home", "question", "information" , "power", "change", "interest", "development ");

   document.write("<b>");
   document.write("NOUN:    "); 
   for (i=0; i<noun.length; i++)
   {
   document.write(" " + noun[i] + "," + "   ");
    }
   document.write("<br>");
   document.write("<br>");
   </script>

<script>
 var verb = new Array ("allow","answer","arrive","ask" , "be", "become" , "begin" , "believe", "bring", "burn", "buy" , "call" , "can" , "decide", "describe", "destroy" , "die" , "do", "drink" , "drive", "eat", "end", "explain", "fall" , "feel" , "hope" , "hurt", "improve",  "jump", "know", "laugh", "learn", "leave", "lie", "listen", "live", "look" , "press" , "promise" , "pull" , "push" , "put" , "read" , "receive",  "recognize", "remember", "repeat" , "rest",  "return");

   document.write("<b>");
   document.write("VERB:     ");
   for (i=0;i<verb.length;i++)
   {
    document.write("    " + verb[i] + "," + "   ");
   }
  document.write("<br>");
  document.write("<br>");

 <script>
   var adj = new Array ("abandoned", "able", "absolute", "adorable", "adventurous", "academic", "acceptable", "adored", "advanced" , "afraid",  "belated",  "beloved", "beneficial", "better",  "best", "careful",  "careles" , "caring",  "circular", "classic", "clean", "clear" , "damaged" , "damp", "dangerous",  "dapper", "daring");

     document.write("<b>");
     document.write("ADJECTIVE:     ");
     for (i=0;i<adj.length;i++)
     {
        document.write("    " + adj[i] + "," + "    ");
      }
     document.write("<br>");
     document.write("<br>");
  </script>

 <script>
  var adv = new Array ("financially","willfully", "abruptly", "endlessly", "firmly", "delightfully",  "quickly", "lightly", "eternally", "delicately","wearily", "sorrowfully","beautifully","truthfully" ,"now", "first", "last", "early", "yesterday", "tomorrow", "today", "later", "regularly", "often", "never", "monthly", "always", "usually", "very", "too", "almost", "also", "only", "enough", "so", "quite", "almost", "rather", "back", "gamely", "helplessly" , "entirely", "absently",  "bodily", "bloodily", "boldly" , "crazily" , "heartbrokenly",  "healthily", "hurtfully");

document.write("<b>");
document.write("ADVERB:     ");
 for (i=0;i<adv.length;i++)
  {
    document.write("     " + adv[i] + "," + "   ");
   }
 document.write("<br>");
 document.write("<br>");

 <script>
    var prep =  new Array ("about", "above", "according to", "along with", "among", "apart from", "around as", "behind ","below", "beneath", "beside", "between", "beyond", "but", "by", "by means of", "concerning", "despite", "down", "except", "for", "excepting", "for", "in case of", "instead of", "into", "like", "near", "next of", "off", "on", "onto", "on top of", "out", "out of", "outside", "round since", "through", "throughout", "till", "under", "until", "up upon", "up", "to", "with", "within", "without");

 document.write("<b>");
 document.write("PREPOSITION:   ");
  for (i=0;i<prep.length;i++)
  {
    document.write("     " + prep[i] + "," + "  ");
  }
  document.write("<br>");
  document.write("<br>");
  </script>

  <script>
    var pronoun = new Array ("all", "another", "any", "anybody", "anyone", "anything", "both","each", "each", "other", "either", "everybody", "everyone", "everything", "few", "he", "her", "hers", "herself", "him", "himself", "his", "I", "it", "its", "itself", "little", "many", "me", "mine");

    document.write("<b>");
    document.write("PRONOUN:    ");
   for (i=0;i<pronoun.length;i++)
   {
     document.write("        " + pronoun[i] + "," + "   ");
   }
   document.write("<br>");
   document.write("<br>");
   </script>

   <script>
      var conj = new Array("for", "and", "nor", "but", "or", "yet", "so", "either", "or", "neither", "nor", "both", "and", "not only", "but", "also", "after all", "in addition", "next", "also", "incidentally", "nonetheless", "as a result", "indeed", "on the contrary", "besides", "in fact", "on the other hand", "consequently", "in other words", "otherwise", "finally", "instead", "still", "for example", "likewise", "then","furthermore", "meanwhile", "hence", "moreover", "thus", "however", "nevertheless");

      document.write("<b>");
      document.write("CONJUNCTION:  " );
      for (i=0;i<conj.length;i++)
      {
        document.write("     " + conj[i] + "," + "  ");
      }
      document.write("<br>");
      document.write("<br>");
      </script>

     <script>
        var interjection = new Array ( "Absolutely", "Achoo", "Ack", "Adios", "Aha", "Ahoy", "Agreed", "Alack", "Alright", "Alrighty", "Alrighty-roo", "Alack", "Alleluia", "All hail", "Aloha", "Amen", "Anytime", "Argh", "Anyhoo", "Anyhow", "As if", "Attaboy", "Attagirl", "Awww", "Awful", "Ay", "bam", "Bah", "hambug", "Begorra", "Behold", "Bingo", "Blah", "Bravo", "Brrr", "Bye", "Cheers", "Ciao", "Cripes", "Crud", "Darn", "Dear", "Doh", "Drat", "Eek", "Encore", "Eureka", "FiddlesticksFie", "Gadzooks", "Gee");

      document.write("<b>");
      document.write("INTERJECTION:     ");
      for (i=0;i<interjection.length;i++)
      {
        document.write("    " + interjection[i] + "! " + "," + "    ");
      }
      document.write("<br>");
      document.write("<br>");
      </script>

      <script>
         var deter = new Array ("the", "a", "an", "another", "no","some", "any", "my", "our", "their", "her", "his", "its", "each", "every" , "certain" , "its", "this", "that", "your", "whose", "little", "|ess", "least", "few", "fewer", "fewest");

          document.write("<b>");
          document.write("DETERMINER: ");
           for (i=0;i<deter.length;i++)
          {
            document.write("    " + deter[i] + "," + "  ");
          }
          document.write("<br>");
          document.write("<br>");
          </script>
         <br>
         <form>
         <center>
         <font size="+1">
            Input Words: <input type = "text" name  = "enter" size = "70"> 
         </form> 
             <input name="parse" type="button" value="parse?">
         </center>
         </font>
          </h4>
         </font>
         </body>
         </body>
         </html>

输出必须是这样的

  1. 从上面的单词中选择
  2. 在输入框中输入
  3. 点击按钮解析?
  4. 显示结果:

例如:她是我的

她——代词

is——介词

我的——代词

4

1 回答 1

0

所以这有几点:

您的代码直接在几个脚本标签中,这意味着它会在页面加载时立即执行 - 显然这是在任何人输入文本之前。

您需要将代码包装成某种函数,然后在输入时调用:

<script>
function parseWords() {
   //All of your code goes here
}
</script>

然后从你的按钮你可能想调用这个函数,我会在按下按钮时假设。

<input name="parse" type="button" value="parse?" onclick="parseWords()">

您的文本输入需要一个 ID,以便我们可以轻松地从中获取数据:

<input id="textInput" type = "text" name  = "enter" size = "70"> 

接下来,您必须从输入中获取数据,然后将其拆分。

function parseWords() {
   var myText = document.getElementById("textInput").value;
   var myWords = myText.split(" ");
}

现在您必须遍历每个单词并找到它们的类型:

function parseWords() {
   var myText = document.getElementById("textInput").value;
   var myWords = myText.split(" ");

   for (int i = 0; i < myWords.length; i++) {
     // Check for your words here and generate the output
   }
}

这不是完整的解决方案,但这些是我认为您的代码有问题的要点。我希望你能从这里找出其余的。

于 2013-09-22T18:36:33.487 回答