1

Javascript の初心者です。ユーザーが入力した配列に基づいてアイテムのリストを作成する単純なフォームを作成しようとしています。配列 x に基づいてアイテムのリストを作成するにはどうすればよいですか?

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
  <head>
    <title></title>
    <script type="text/javascript">
    function checkwarranty()
    {
      var x = new Array();

      x[0] = document.getElementById('clientname').value;
      x[1] = document.getElementById('select').value;
      x[2] = document.getElementById('expirationdate').value;
      x[3] = document.getElementById('notifyon').value;
    }
    </script>
  </head>
  <body>
    <form>
      <table border="1">
        <tr>
          <td>Client Name:</td>
          <td>
            <input type="text" name="clientname" id="clientname">
          </td>
        </tr>
        <tr>
          <td>Device Type:</td>
          <td>
            <select id="select">
              <option value="Server">Server</option>
              <option value="Server">Firewall</option>
              <option value="Server">Domain</option>
              <option value="Server">Desktop</option>
            </select>
          </td>
        </tr>
        <tr>
          <td>Warranty Expires on:</td>
          <td>
            <input type="date" name="expirationdate" id="expirationdate">
          </td>
        </tr>
        <tr>
          <td>Notify On:</td>
          <td>
            <input type="date" name="notifyon" id="notifyon">
          </td>
        </tr>
      </table><br>
      <input type="button" name="submit" value="submit" onclick="checkwarranty()">
    </form>
  </body>
</html>
4

1 に答える 1

1

多次元配列はあなたが望むものです。これを試して

var list = [];

function checkwarranty()
{
    var x = [];

    x[0] = document.getElementById('clientname').value;
    x[1] = document.getElementById('select').value;
    x[2] = document.getElementById('expirationdate').value;
    x[3] = document.getElementById('notifyon').value;

    list.push(x);
}

詳細については、http://www.w3schools.com/jsref/jsref_obj_array.aspを確認してください。

于 2013-08-18T07:31:11.713 に答える