gpt4 book ai didi

javascript - jQuery:获取 HTML 表格第四行(仅)的第一列值

转载 作者:搜寻专家 更新时间:2023-10-31 21:55:35 24 4
gpt4 key购买 nike

我有一个名为 resultGridTable 的表。我有一个要在表的每一行上执行的 jQuery 函数。在函数中,“this”表示一行。

  1. 对于第四行,我需要提醒(第四行的)第一列值。我有以下代码;但它不起作用。我们怎样才能让它发挥作用?

  2. 对于第五行,我需要提醒该行的列数。我们该怎么做?

  3. 在第六行的第二列中,我有两个按钮 (input type="submit")。我需要提醒第二个按钮的文本/值。 (第二个按钮有一个名为“secondButton”的类)我们该怎么做呢?

代码如下:

$('#resultGridTable tr').each(function (i) 
{
//"this" means row
//Other operations in the row. Common for all rows

if(i==3)
{
//Specific Operation for fourth row
var columnValue = $(this 'td:nth-child(0)').val();
alert(columnValue);
}
});

阅读 Material :

  1. jQuery Code: Starting from Parent to Child; not from Child to Parent

  2. How to get value of first column in current row in html table using jQuery

  3. How to get the first row's last column of an Html table using jQuery

最佳答案

不同的是,您可以在这里混合使用 DOM 和 jQuery 以获得良好的效果,因为您已经在表中设置了固定的偏移量:

var t = document.getElementById('resultGridTable');

// jQuery to get the content of row 4, column 1
var val1 = $(t.rows[3].cells[0]).text();

// no jQuery here to get that row length!
var val2 = t.rows[4].cells.length;

// DOM access for the cell, and jQuery to find by class and get the text
var val3 = $('.secondButton', t.rows[5].cells[1]).text();

这些应该都比使用选择器快得多。

关于javascript - jQuery:获取 HTML 表格第四行(仅)的第一列值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10796559/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com