-1

5つのテキストフィールドを2つの異なる形式に連結し、それぞれの特定の形式を同じフォーム/ページの2つの別々のテキスト領域に出力しようとしています。

添付されたコードはTextArea1に出力するために正常に機能しますが、2番目のTextArea2には出力されません。

したがって、C + A、B + D、EでTextArea1にデータを入力します。そして、C + D、A、B+EでTextArea2にデータを入力します。

任意のヘルプ/アドバイスをいただければ幸いです。ありがとうございました。

    <html>
    <script type="text/javascript">
    function setName()
    {document.forms[0].TextArea1.value = document.forms[0].TextC.value + ' ' + document.forms[0].TextA.value + ', ' + document.forms[0].TextB.value + ' ' + document.forms[0].TextD.value + ', ' + document.forms[0].TextE.value}
    </script>



    <script type="text/javascript">
    function setName()
    {document.forms[0].TextArea2.value = document.forms[0].TextC.value + ' ' + document.forms[0].TextD.value + ', ' + document.forms[0].TextA.value + ', ' + document.forms[0].TextB.value + ' ' + document.forms[0].TextE.value}
    </script>

    <head>
    </head>
    <body>
    <form method="post">
    <table >

<tr>
  <td style="width: 421px">
  <input name="TextA" onkeyup="setName()" type="text" />&nbsp; </td>
</tr>


<tr>
  <td style="width: 421px">
  <input name="TextB" onkeyup="setName()" type="text" /> </td>
</tr>


<tr>
  <td style="width: 421px">
  <input name="TextC" onkeyup="setName()" type="text" /> </td>
</tr>


<tr>
  <td style="width: 421px">
  <input name="TextD" onkeyup="setName()" type="text" /> </td>
</tr>


<tr>
  <td style="width: 421px">
  <input name="TextE" onkeyup="setName()" type="text" /> </td>
</tr>


<tr>
  <td style="width: 421px"><strong>C+A, B+D, E</strong><br />
  Created this outcome:<br />
  <input name="TextArea1" onfocus="setName()" style="width: 286px; height: 90px" type="text" wrap="hard" />
  <br />
  </td>
</tr>

<tr>
  <td style="width: 421px"><strong>C+D, A, B+E</strong><br />
  Created this outcome:<br />
  <input name="TextArea2" onfocus="setName()" style="width: 286px; height: 90px" type="text" wrap="hard" /></td>
</tr>

<tr>
  <td style="width: 421px"><strong>Clear Form</strong><br />
  <input name="Reset2" type="reset" value="reset" />&nbsp; </td>
</tr>
      </table>
    </form>
    </body>
    </html>
4

3 に答える 3

4

同じ名前の2つの関数があります。2番目は最初を上書きします。

于 2012-11-26T17:09:45.003 に答える
1

両方の関数に同じ関数名を使用しています。2番目のものは最初のものをオーバーライドしています。setNameTwo()またはそのようなものに変更すると、正常に動作するはずです。

于 2012-11-26T17:12:23.610 に答える
0

関数がsetName()2回定義されています。最初のものは呼び出されていますが、2番目のものは呼び出されていません。2番目のコードをsetName最初のコードに、すでに存在するコードと一緒に配置すると、機能します。

<script type="text/javascript">
function setName()
{
    document.forms[0].TextArea1.value = document.forms[0].TextC.value + ' ' + document.forms[0].TextA.value + ', ' + document.forms[0].TextB.value + ' ' + document.forms[0].TextD.value + ', ' + document.forms[0].TextE.value;
    document.forms[0].TextArea2.value = document.forms[0].TextC.value + ' ' + document.forms[0].TextD.value + ', ' + document.forms[0].TextA.value + ', ' + document.forms[0].TextB.value + ' ' + document.forms[0].TextE.value
}
</script>
于 2012-11-26T17:11:28.120 に答える