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

时间:2017-11-27 07:10:45

标签: jquery html json

嗨,我有动态数据,如果是的话我会生成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>

我想要这样的数据:

    [
{
id: 1,
newValue:"assignment",
oldValue:5,
},
{
id: 2,
newValue:"assignment",
oldValue:5,
},
{
id: 3,
newValue:"assignment",
oldValue:5,
}
]

这里的HiddenField1在TD == Id,第二个输入文本框是newValue,第三个hiddenfild是&#34; oldValue&#34;

0 个答案:

没有答案