序列化表tr数据? [英] Serialize table tr data?

查看:186
本文介绍了序列化表tr数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用序列化表单:

I'm serializing my form using :

formVals = $('#formID').serialize();

但是我还有一张要序列化并将其添加到formVals的表,可以吗?我已经尝试过了:

But I also have a table that I'd like to serialize and add it to formVals Can that be done? I've tried :

$('#tableName').find('tr').each(function(){
    formVals = $(this).text().serialize();
})

但这会导致

未捕获的TypeError:$(...).text(...).serialize不是函数

Uncaught TypeError: $(...).text(...).serialize is not a function

我想做的是从每个tr中获取文本,并将其与退出日期一起添加为formVals的新条目.有办法吗?

What I want to do is take the text from each tr and add it as a new entry to formVals along with the exiting date. Is there way to do this?

更新

一行看起来像这样:

<tr id="12354-515-asd">
<td>Today</td>
<td>0000</td>
<td>Monday</td>
<td>2345</td>
</tr>

要添加到formVals的期望值为: 12354-515-asd=Today0000Monday2345

The expected values to be added to formVals is: 12354-515-asd=Today0000Monday2345

推荐答案

您需要将每个参数连接到formVals.

You need to concatenate each parameter to formVals.

formVals = $("#formID").serialize();
$('#tableName').find('tr').each(function(){
    formVals += '&' + this.id + '=' + encodeURIComponent($(this).text());
});

这篇关于序列化表tr数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆