如何使用javascript获取特定表格单元格中的输入值? [英] How can I get the value of an input in a specific table cell using javascript?

查看:146
本文介绍了如何使用javascript获取特定表格单元格中的输入值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何使用javascript在特定的表格单元格中获取输入值的价值?

I'm wondering how can I get the value of an input in a specific table cell using javascript?

<td><input type="text"/></td>

我假设得到一个特定的 innerHTML 单元格非常简单,例如:

I assume getting the innerHTML of a specific cell is quite simple, for example:

var x = document.getElementById("tabela").rows[2].cells[3].innerHTML

但这给我只是输入没有它的。将 .value 添加到行的末尾不起作用。我很感激你的帮助!

but this gives me just the input without it's value. Adding .value to the end of the line doesn't work. I would appreciate your help!

推荐答案

如果您没有任何 id 你所在的元素,然后你可以通过以下方式获得 td 的第一个孩子:

If you don't have any id on the element you are after, then you could get the first child of the td by:

var x = document.getElementById("tabela").rows[n].cells[n].children[0].value;

或者如果您希望第一个孩子具体输入,那么:

Or if you want the first child to be specific to input then:

var x = document.getElementById("tabela").rows[n].cells[n].getElementsByTagName('input')[0].value;

这篇关于如何使用javascript获取特定表格单元格中的输入值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆