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 回答