简体   繁体   English

在相同的tr jQuery中获取td的val

[英]Getting the val of td in same tr jQuery

I was wondering how i could console.log the value of 我想知道如何控制.log的价值

$('<td>').text(result[i].id),

field if I call the function on the input button: 字段,如果我在输入按钮上调用该函数:

$('<tr>').append(
            $('<td>').text(result[i].id),
            $('<td>').text(result[i].naam),
            $('<td>').text(result[i].brouwer),
            $($('<input onclick="getAllData(this)" type="button" value="View" />'))
        ).appendTo('#output');

Given the following code: 给出以下代码:

getAllData = function(a) {
  console.log(a.parentElement.firstChild.textContent);
}

result=[{'id': 1, 'naam': 'foo', 'brouwer': 'bar'}];
result.forEach(function( r, i, result ) {
    $('<tr>').append(
                     $('<td>').text(result[i].id),
                     $('<td>').text(result[i].naam),
                     $('<td>').text(result[i].brouwer),
                     $($('<input onclick="getAllData(this);" type="button" value="View" />'))
                    ).appendTo('#output');
});

And a table like so: 和这样的表:

<table id='output'>
  <tr></tr>
</table>

you'll get what you're looking for. 你会得到你想要的东西。

See this fiddle for the working example. 看到这个小提琴的工作示例。

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

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