开发者

jQuery: Get all input vals within a table and serialize

Given the following table struct开发者_StackOverflow社区ure, how would I get all the input vals within a table when the .button is clicked?

<table>
    <tr>
      <td><input value="1" name="A" type="text" /><td>
    </tr>
    <tr>
      <td><input value="2" name="B" type="text" /><td>
    </tr>
    <tr>
      <td><input value="3" name="C" type="text" /><td>
    </tr>
    <tr>
      <td><div class="button"></div><td>
    </tr>
</table>

This is the jquery I have so far:

$('.button').click(function() {
    alert($(this).parent('table').('input').serialize());
});

The function isn't working though, it's not finding the input in the table I guess...


table is not the parent of the button, td is... try :

$(this).closest('table').find('input').serialize()


not very direct, but should give you the understanding:

http://jsfiddle.net/5D5NG/3/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜