获取被点击的table行元素值
Get the clicked table row element value
我知道这已经在这里问过了。我提到了这个 Link 1 , Link 2 但在 jquery 移动设备中工作相同无法获得价值。我想获取A列的值如何获取这个。
这是Fiddle我试过的
代码如下:
onclick="deleteRow(this)"
function deleteRow(r) {
$(r).parent().parent().hide();
var Something = $(r).closest('tr').find('td:eq(1)').text();
alert(Something);
// this one gave the input element as child
alert($(r).parent().parent().children().children().html);
alert($(r).parent().parent().children().children().text());
}
也检查这个Fiddle 1
您要查找的文本实际上是第一个 td
中 input
的值,因此您需要获取该元素的 val()
,而不是 text()
的 td
。另请注意 eq()
采用从零开始的索引,因此您需要使用 0
获取行的第一个 td
。试试这个:
function deleteRow(r) {
var $row = $(r).closest('tr').hide();
var Something = $row.find('td:eq(0) input').val();
alert(Something);
}
我知道这已经在这里问过了。我提到了这个 Link 1 , Link 2 但在 jquery 移动设备中工作相同无法获得价值。我想获取A列的值如何获取这个。
这是Fiddle我试过的
代码如下:
onclick="deleteRow(this)"
function deleteRow(r) {
$(r).parent().parent().hide();
var Something = $(r).closest('tr').find('td:eq(1)').text();
alert(Something);
// this one gave the input element as child
alert($(r).parent().parent().children().children().html);
alert($(r).parent().parent().children().children().text());
}
也检查这个Fiddle 1
您要查找的文本实际上是第一个 td
中 input
的值,因此您需要获取该元素的 val()
,而不是 text()
的 td
。另请注意 eq()
采用从零开始的索引,因此您需要使用 0
获取行的第一个 td
。试试这个:
function deleteRow(r) {
var $row = $(r).closest('tr').hide();
var Something = $row.find('td:eq(0) input').val();
alert(Something);
}