获取表的所有行和列的每个元素的值
Get Value of each Element of all Row and Column of a Table
好吧,我有一个表格,其中包含不同的元素,如文本框,文本区域和复选框。
我正在使用以下代码:
$('#tablaCorrectiva tr').not(':first').each(function() {
alert($(this).children("td:nth-child(1)").val()); //Get BLANK
alert($(this).children("td:nth-child(1)")); // GET "[object Object]"
}
但我没有得到元素的值。
我尝试过:
$(this).children("td:nth-child(3)").find('.acc_correc').val()
但我被定义不清。
请帮忙
试试这个
alert($(this).children("td:nth-child(3)").find(':input').val());
使用
alert($(this).children("td:nth-child(1)").html());
而不是
alert($(this).children("td:nth-child(1)").val());
检查小提琴
试试这个鳕鱼
<table id=tablaCorrectiva >
<thead>
<tr><th>code</th></tr>
</thead>
<tbody>
<tr><td><input value="pippo"></td></tr>
<tr><td><input value="pluto"></td></tr>
<tr><td><input value="paperino"></td></tr>
</tbody>
<table>
/*Suppose the first TR is head and it is under <thead></thead>*/
$('#tablaCorrectiva > tbody > tr > td').each(function(index,value) {
alert($(value).find("textarea,input").val());
});
相关文章:
- React - 从 DOM 元素获取组件以进行调试
- 如何使用 JQuery 从相对元素获取 html 文本
- 从同一域上的 iframe 中的元素获取值
- 使用本机 Javascript 从 DOM 元素获取选择器字符串
- 使用jquery从另一个元素获取使用id的输入的id
- 如何从角度元素获取编译的节点值
- 如何为不同的元素获取不同的父类
- 从 jQuery 中的子元素获取父 tr 元素
- 当浮点部分为空时,从 JQuery 中的输入元素获取数字值不起作用
- 从 XML 元素获取文本
- 从音频元素获取音频样本
- 从所选元素 html 上方的元素获取属性值
- 使用 jQuery.data 从 dom 元素获取布尔值
- 如何通过jquery从某个元素获取部分文本
- 从输入元素获取表单和表单数据对象
- 从动态元素获取挖空视图的大小
- 从中继器循环中显示的子自定义元素获取正确的上下文.奥蕾莉亚
- 如何使用 JavaScript 或 JQuery 从输入类型=文件 html 元素获取文件名
- 从父元素获取 ID 并将它们放在数组中
- 尝试从选项元素获取 HTML