Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/413.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用Jquery获取记录表并使用AJAX将其发送到服务器?_Javascript_Jquery_Json_Ajax - Fatal编程技术网

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

Javascript 如何使用Jquery获取记录表并使用AJAX将其发送到服务器?,javascript,jquery,json,ajax,Javascript,Jquery,Json,Ajax,我有一张像下面这样的桌子 <table cellspacing="0" rules="all" border="1" id="ContentPlaceHolder1_GridView1" style="border-collapse:collapse;" class="table table-striped"> <tbody> <tr> <th scope="col">&nbsp;</t

我有一张像下面这样的桌子

<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>
it警报
值=未定义


我正在尝试获取如下值

在您的警报消息中尝试此值

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

$("#ContentPlaceHolder1_GridView1 .checkBoxClass input[type='checkbox']:checked").closest("tr").find("td:eq(1)").text()
将适用于BillNo(但最好在html中为此列添加一个类或数据标记,就像您对actualAmount所做的那样)

实际金额:

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

如果希望选中该复选框并将该值保存在对象数组中的所有行

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() });
});

我希望它能有所帮助

这把小提琴与您的代码有什么关系?注:
距离输入最近的(“td”)
是包含输入的
td
。你可能想要它的下一个兄弟姐妹instead@Jaromandax不,我只是试着看看它是否显示下一个值。但我只想得到第二个和第六个td值。每一行有10个td,为了说明这一点,我删除了一些td元素,但最接近输入的是包含输入的td,因此,您发布的代码完全不足如果您已经有了一个可以完成几乎所有需要的工作的代码段,那么问题出在哪里?@dfsq我正在尝试用我的表记录创建一个类似于该代码段的数组,并将其传递给服务器ajax@A.lglesias我希望您的代码是正确的,但当我执行
alert(values)时,它不会发出任何警报
在代码
值之后是一个对象数组。要提醒其值,可以执行
alert(JSON.stringify(values))
@A.lglesias correct brother谢谢,我应该如何通过ajax,ajax中的数据类型是什么,以及我应该在webmethod中给出的数据类型?这里有一个示例
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() });
});