jQuery:获取表中的所有输入值并序列化 [英] jQuery: Get all input vals within a table and serialize
本文介绍了jQuery:获取表中的所有输入值并序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
鉴于以下表格结构,当点击 .button
时,我如何获得表格中的所有输入值?
Given the following table structure, 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>
这是我目前使用的 jquery:
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
不是按钮的父级,td
是... try :
table
is not the parent of the button, td
is... try :
$(this).closest('table').find('input').serialize()
这篇关于jQuery:获取表中的所有输入值并序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文