Jquery 如何将表td数据转换为特定行的JSON?

Jquery 如何将表td数据转换为特定行的JSON?,jquery,html,json,Jquery,Html,Json,嗨,我有动态数据,我正在生成HTML表,如果它。现在我想分别提交每一行。但我无法从每一列中获取数据。请导游。以下是我的表格结构: <table id="tblQuizzes" class="table table-striped"> <thead> <tr> <th>Student Name</th> <th>AGN Test 1</th> <th&

嗨,我有动态数据,我正在生成HTML表,如果它。现在我想分别提交每一行。但我无法从每一列中获取数据。请导游。以下是我的表格结构:

<table id="tblQuizzes" class="table table-striped">
<thead>
    <tr>

        <th>Student Name</th>
        <th>AGN Test 1</th>
        <th>Assignment</th>
        <th>Food Chef</th>
    </tr>
</thead>
<tbody>
    <tr id="tr_1">
        <td>
            Studet 1


        </td>
        <td>
            <input name="Id_1_2" value="29" form="form1" type="hidden">
            <input class="Id" style="width:30px;" value="9.00" name="1_2" form="form1">
            /10.00                                                <input name="OldValue_1_2" value="9.00" form="form1" type="hidden">



        </td>
        <td>
            <input name="Id_1_3" value="" form="form1" type="hidden">
            <input class="Id" style="width:30px;" value="" name="1_3" form="form1">
            /10.00                                                <input name="OldValue_1_3" value="" form="form1" type="hidden">



        </td>
        <td>
            <input name="Id_1_4" value="19" form="form1" type="hidden">
            <input class="Id" style="width:30px;" value="5.50" name="1_4" form="form1">
            /10.00                                                <input name="OldValue_1_4" value="5.50" form="form1" type="hidden">



        </td>
        <td><input class="btn btn-primary actions" form="form1" value="Save" type="submit"></td>
    </tr>
    <form method="POST" id="form1" action="Controller/Method"></form>


    <tr id="tr_2">
        <td>Student 2</td>
        <td>
            <input name="Id_2_2" value="" form="form2" type="hidden">
            <input class="Id" style="width:30px;" value="" name="2_2" form="form2">
            /50.00                                                <input name="OldValue_2_2" value="" form="form2" type="hidden">



        </td>
        <td>
            <input name="Id_2_3" value="22" form="form2" type="hidden">
            <input class="Id" style="width:30px;" value="17.00" name="2_3" form="form2">
            /50.00                                                <input name="OldValue_2_3" value="17.00" form="form2" type="hidden">



        </td>
        <td>
            <input name="Id_2_4" value="" form="form2" type="hidden">
            <input class="Id" style="width:30px;" value="" name="2_4" form="form2">
            /50.00                                                <input name="OldValue_2_4" value="" form="form2" type="hidden">



        </td>
        <td><input class="btn btn-primary actions" form="form2" value="Save" type="submit"></td>
    </tr>
    <form method="POST" id="form2" action="Controller/Method"></form>


    <tr id="tr_3">
        <td>
            Student 3


        </td>
        <td>
            <input name="Id_3_2" value="" form="form3" type="hidden">
            <input class="Id" style="width:30px;" value="" name="3_2" form="form3">
            /50.00                                                <input name="OldValue_3_2" value="" form="form3" type="hidden">



        </td>
        <td>
            <input name="Id_3_3" value="30" form="form3" type="hidden">
            <input class="Id" style="width:30px;" value="0.00" name="3_3" form="form3">
            /50.00                                                <input name="OldValue_3_3" value="0.00" form="form3" type="hidden">



        </td>
        <td>
            <input name="Id_3_4" value="" form="form3" type="hidden">
            <input class="Id" style="width:30px;" value="" name="3_4" form="form3">
            /50.00                                                <input name="OldValue_3_4" value="" form="form3" type="hidden">



        </td>
        <td><input class="btn btn-primary actions" form="form3" value="Save" type="submit"></td>
    </tr>
    <form method="POST" id="form3" action="Controller/Method"></form>




</tbody>

这里的HiddenField1在TD==Id中,第二个输入文本框是newValue,第三个hiddenfild是“oldValue”

我不是很确定,但我想你想要这样的东西。 请参阅下面的代码片段

注意我添加了
e.preventDefault()仅用于防止提交操作在控制台中记录输出。你需要移除它

$(文档).ready(函数(){
$('input[type=“submit”]”)。单击(函数(e){
var输出=[];
$(this).parents('tr').find('td:gt(0):lt(3)).each(function(){
var obj={
id:$(this).find('input')[0]。值,
newValue:$(this).find('input')[1]。值,
oldValue:$(this).find('input')[2]。值
};
输出推力(obj);
});
控制台日志(输出);
e、 预防默认值();
});
});

学名
活动星系核试验1
分配
厨师长
双头螺栓1
/10.00
/10.00
/10.00
学生2
/50.00
/50.00
/50.00
学生3
/50.00
/50.00
/50.00
    [
{
id: 1,
newValue:"assignment",
oldValue:5,
},
{
id: 2,
newValue:"assignment",
oldValue:5,
},
{
id: 3,
newValue:"assignment",
oldValue:5,
}
]