简体   繁体   English

如何使用Jquery获取记录表并使用AJAX将其发送到服务器?

[英]How to get the table of records using Jquery and send it to server using AJAX?

I have a table like below 我有一个像下面的桌子

<table cellspacing="0" rules="all" border="1" id="ContentPlaceHolder1_GridView1" style="border-collapse:collapse;" class="table table-striped">
    <tbody>
        <tr>
            <th scope="col">&nbsp;</th>
            <th scope="col">Bill NO</th>
            <th scope="col">Date</th>
            <th scope="col">Description</th>
            <th scope="col">Type</th>
            <th scope="col">Amount</th>
        </tr>
        <tr>
            <td><input id="Checkbox0" class="checkBoxClass" type="checkbox">/td>
            <td>111</td>
            <td>12-22-2014</td>
            <td>computer problem</td>
            <td>Invoice</td>
            <td class="ActualAmount">7689.00</td>
        </tr>
        <tr>
            <td><input id="Checkbox1" class="checkBoxClass" type="checkbox">/td>
            <td>112</td>
            <td>12-22-2014</td>
            <td>Printer problem</td>
            <td>Invoice</td>
            <td class="ActualAmount">7689.00</td>
        </tr>
    </tbody>
</table>

I am trying to get the value of BillNo and ActualAmount if checkbox is selected on that row 如果在该行上选中了复选框,我试图获取BillNoActualAmount的值

First I try to get the value of the row using this below code 首先,我尝试使用以下代码获取行的值

alert('value = ' + $("#ContentPlaceHolder1_GridView1 .checkBoxClass input[type='checkbox']:checked").closest("td").val())

it alert value = undefined 它警报 value = undefined

I am trying to get the value like this Jfiddle 我正在尝试获得像Jfiddle这样的价值

If you want to get all rows that has that checkbox checked and save that values in an array of objects... 如果要获取所有已选中该复选框的行,并将该值保存在对象数组中...

var values = [];

$('table#ContentPlaceHolder1_GridView1 input.checkBoxClass:checked').each(function() {
    var $row = $(this).closest('tr').children('td');
    values.push({ 'billno': $row.eq(1).text(), 'amount': $row.eq(5).text() });
});

I hope it helps 希望对您有所帮助

在您的警报消息中尝试此操作

$("#ContentPlaceHolder1_GridView1  input[type='checkbox'].checkBoxClass:checked").parent().next().html()

Something like 就像是

$("#ContentPlaceHolder1_GridView1 .checkBoxClass input[type='checkbox']:checked").closest("tr").find("td:eq(1)").text()

will work for BillNo (but it should be better to add a class or a data-tag in your html for this column, as you did for actualAmount). 将对BillNo有效(但最好在html中为此列添加类或数据标签,就像对ActualAmount一样)。

For actual Amount : 对于实际金额:

$("#ContentPlaceHolder1_GridView1 .checkBoxClass input[type='checkbox']:checked").closest("tr").find("td.ActualAmount").text()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM