简体   繁体   English

获取单击的表行元素值

[英]Get the clicked table row element value

I know this already asked here. 我知道这已经在这里问了。 I referred this Link 1 , Link 2 but working the same in jquery mobile not able to get the value. 我引用了此Link 1Link 2,但是在jquery mobile中以相同的方式无法获取该值。 I want to get column A value how to get this one. 我想获取列A值如何获取此值。

Here is the Fiddle what i tried 这是我尝试过的小提琴

Code is like: 代码就像:

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

} }

check this also Fiddle 1 同时检查此小提琴1

The text you're looking for is actually the value of the input within the first td , so you need to get the val() of that element, not the text() of the td . 您要查找的文本实际上是第一个td内的input值,因此您需要获取该元素的val() ,而不是tdtext() Also note that eq() takes the index which is zero-based, so you need to use 0 to get the first td of the row. 还要注意, eq()采用从零开始的索引,因此您需要使用0来获取行的第一个td Try this: 尝试这个:

function deleteRow(r) {
    var $row = $(r).closest('tr').hide();
    var Something = $row.find('td:eq(0) input').val();
    alert(Something);
}

Updated fiddle 更新的小提琴

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

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