Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/458.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/69.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 选中“标题”复选框时,获取每个选中行的特定单元格值_Javascript_Jquery_Html_Asp.net_Html Table - Fatal编程技术网

Javascript 选中“标题”复选框时,获取每个选中行的特定单元格值

Javascript 选中“标题”复选框时,获取每个选中行的特定单元格值,javascript,jquery,html,asp.net,html-table,Javascript,Jquery,Html,Asp.net,Html Table,我有gridview的标题复选框和每行的复选框。。单击标题复选框时,我需要检查是否选中了子复选框,如果选中,我需要获取所有选中行的第三个单元格值 为此,我使用下面的Javascript函数: function toggleSelection(source) { $("#MainContent_gvCG input[id*='chkCert']").each(function (index) { if(source.checked) { if (t

我有gridview的标题复选框和每行的复选框。。单击标题复选框时,我需要检查是否选中了子复选框,如果选中,我需要获取所有选中行的第三个单元格值

为此,我使用下面的Javascript函数:

 function toggleSelection(source) {
    $("#MainContent_gvCG input[id*='chkCert']").each(function (index) {
        if(source.checked) {
            if (this.checked) {

               ////Here i need to access the third cell values of all rows

            }
        }
    });
}
为了更好地理解,示例表格式:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
 </script>
 <table border="1">
  <tr>
    <th>CFS Name</th>
    <th>Amount</th>
    <th>TCFSA</th>
    <th>CODEX</th>
    <th><input type="checkbox" id="chkHeader"/></th>
  </tr>
  <tr>
    <td>TRANSWORLD GLS INDIA</td>
    <td>Abc</td>
    <td>cg</td>
    <td>de</td>
    <td><input type="checkbox" class="chkCert"></td>
  </tr>
  ................
  ...............
  ..............
  </table>
这是我的gridview:

     <asp:GridView ID="gvPRCertInfo" runat="server" AutoGenerateColumns="False" GridLines="None"                     
           OnRowDataBound="gvPRCertInfo_RowDataBound"
            CssClass="data responsive">
             <Columns>
                <asp:TemplateField HeaderText="Select" SortExpression="">
                 <HeaderTemplate>
                   <asp:CheckBox ID="chkboxSelectAll" runat="server" AutoPostBack="true" onclick="toggleSelection(this);"  OnCheckedChanged="chkboxSelectAll_CheckedChanged"/>
                     </HeaderTemplate>
                       <ItemTemplate>
                        <asp:CheckBox ID="chkCert" AutoPostBack="true" OnCheckedChanged="chkCert_CheckedChanged"  runat="server" />                                    
                         <input type="hidden" id="hdnCertId" runat="server" value='<%# DataBinder.Eval(Container.DataItem, "CertId") %>' />
                       </ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="CertificateID" HeaderText="Certificate ID" HeaderStyle-HorizontalAlign="Center" />
         ....................
         .....................
         ..............
       </Columns>                            
   </asp:GridView>
请任何人对此提出建议,如何访问所有选中行的第三个单元格值。。除此之外,任何更好的解决方案都是受欢迎的

修改代码:

function toggleSelection(source) {
    $('#<%= gvPRCertInfo.ClientID %> input[id*="chkCert"]').each(function () {
            if (source.checked) {
                alert("source checked");
                if (this.checked) {
                    alert("child chk");
                    var allVlues = $(this).closest('tr').children('td:eq(4)').html();
                    alert(allVlues);

                }
            }
        });
    }

我无法向Child chk发出此警报,请任何人在此方面提供帮助。

如果您可以将此视为一个简单的客户端数据收集,请选择您想要的。一个例子:

var $thirdCell = $(this).parent().children(':nth-child(3)');
console.log('Text: ', $thirdCell.text());
console.log('HTML: ', $thirdCell.html());
根据“值”的含义,您可以获取文本或HTML。

尝试$this.parent.parent.find'td:eq2.text;。还要注意$MainContent\u gvCG input.chkCert:checkbox.each…中的更改

功能切换SelectionSource{ $MainContent\u gvCG input.chkCert:checkbox.eachfunction index{ ifsource.checked{ 如果这个被选中了{ 让thirdVal=$this.parent.parent.find'td:eq2'.text; console.logthirdVal; } } }; } CFS名称 数量 TCFSA 法典 环球GLS印度 Abc cg 判定元件 测验 mnl opq xyz
$this.prev.prev;将选择第三个td。然后使用.text获取其中的内容。建议在控制台中进行游戏。这是什么?如果你做了类似window.AA=这样的事情;作为函数的第一行,然后您可以从控制台中的最后一次函数调用访问AA,并查看您假设情况并非如此的情况。使用$MainContent\u gvCG输入[id*='chkCert']:选中,这将只循环通过选中的复选框,这样您就不必使用this.checked作为示例表格式,因为我可以在其中看到class=chkCert而不是id。更新你合适的样本表你能研究一下这个问题吗?我已经更新了我的代码。。我无法发出警报如果this.checked{alertchild chk;…此检查针对每行复选框…我无法进入此if循环…我如何进入此复选框…您是否有任何想法正确。正如我在上面的评论中所问,此值是多少?您如何保证您的函数正在执行?