从输入字段javascript,Jquery访问表最后一行值

时间:2013-09-21 13:36:32

标签: javascript jquery

你好我有下面提到的这个表结构

<table id="dataTable" class="center">
  <thead>
    <tr>
      <th>ID</th>
      <th>Location</th>
      <th>Type</th>
      <th>Latitiude</th>
      <th>Longitude</th>
      <th>Time Stamp</th><th >Status</th>
      <th></th></tr>
  </thead>
  <tbody>
    <tr id="saved">
      <td>10</td>
      <td>Sydney Yatch</td>
      <td>Yatch</td>
      <td>-33.848791</td>
      <td>151.218052</td>
      <td>2013-09-19 23:42:20</td>
      <td><input type="text" id="status" name="isSaved" value="1" /></td>
      <td><a href=db.php?action=delete&id=10>Delete</a> </td>
    </tr>
    <tr id="saved">
      <td>11</td>
      <td>Millers Point</td>
      <td>Point</td>
      <td>-33.858627</td>
      <td>151.204491</td>
      <td>2013-09-19 23:44:19</td>
      <td><input type="text" id="status" name="isSaved" value="1" /></td>
      <td><a href=db.php?action=delete&id=11>Delete</a> </td>
    </tr>
    <tr id="saved">
      <td>12</td>
      <td>Kot Pindi Das</td>
      <td>Restraunt</td>
      <td>31.740665</td>
      <td>74.230499</td>
      <td>2013-09-19 23:46:35</td>
      <td><input type="text" id="status" name="isSaved" value="1" /></td>
      <td><a href=db.php?action=delete&id=12>Delete</a> </td>
    </tr>
    <tr id="saved">
      <td>13</td>
      <td>Connto</td>
      <td>Island</td>
      <td>-33.848007</td>
      <td>151.171618</td>
      <td>2013-09-20 21:23:18</td>
      <td><input type="text" id="status" name="isSaved" value="1" /></td>
      <td><a href=db.php?action=delete&id=13>Delete</a> </td>
    </tr>
    <tr id="unSaved">
      <form method="get" action="db.php" ><td><input type="text" name="id" readonly value="15"/></td>
        <td> <input type="text" id="location" name="location" placeholder="Enter Location" /> </td>
        <td> <input type="text" name="type" placeholder="Enter Type" /> </td>
        <td> <input type="text" name="lat" readonly id="lat" /> </td>
        <td> <input type="text" name="long" readonly id="long" /> </td>
        <td>2013-09-21 17:35:14</td>
        <td ><input  type="text" id="status" name="isSaved" value="0" /></td>
        <td><input type="submit" value="Update" name="action" /></td>
      </form>
    </tr>
  </tbody>
</table>

现在我想要的是从id = isSaved的最后一行的文本框中访问该值 通过使用jquery或javascript

3 个答案:

答案 0 :(得分:0)

如果你正在使用jquery并且id很简单

var val = $('#isSaved').val()

答案 1 :(得分:0)

$('input[name=isSaved]').last().val();

如有疑问,请查看Jquery网站上的文档

答案 2 :(得分:0)

我建议:

var myValue = $('#dataTable input:last-child').val();