在Javascript中访问表格单元格的内容 [英] Accessing the contents of a table cell in Javascript

查看:81
本文介绍了在Javascript中访问表格单元格的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个嵌套在HTML表格单元格中的复选框。我如何从Javascript访问内部复选框?我见过的所有例子都改变了内部HTML本身或视觉属性,这并不是我所感兴趣的。我试过了childNodes数组,但它显然是空的。

$ b $如果你不使用jQuery,那么你可以这样做:

  document.getElementsByTagName( '输入'); 

然后通过循环来找到一个复选框,并且parentNode是表格单元格。



或者非常简单地将ID添加到该复选框。


I've got a checkbox nested inside a table cell element in HTML. How can I access the inner checkbox from Javascript? All of the examples I've seen alter the inner HTML itself, or the visual properties, which is not what I'm interested in. I've tried the childNodes array, but it's empty, apparently.

解决方案

If you are not using jQuery then you could do:

document.getElementsByTagName('input');

And then cycling through them to find one that is checkbox and parentNode is table cell.

Or very simply add ID to that checkbox.

这篇关于在Javascript中访问表格单元格的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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