-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 に答える