gpt4 book ai didi

javascript - 如何在jquery中获取动态表数据中文本框的值

转载 作者:行者123 更新时间:2023-11-30 13:50:35 25 4
gpt4 key购买 nike

我创建了一个带有文本输入框的表格。我想获取 tr 元素中文本框值的值。我该怎么做?

$(document).on('click', '.overtime_send', function(){

$('#employee_table tr').each(function(row, tr){

var asd = $(tr).find('td:eq(3)').text();//get the value
var asd01 = $(tr).find('td:eq(4)').text();//not get the value of the text box
alert(asd);
});

});

上面的代码是获取表行的所有静态内容。如何将文本值获取到表数据中的变量中?

最佳答案

使用 .find('input') 因为您在 tr.val() 中只有一个输入来获取值(value)。

let your_array = [];

$(document).on('click', '.overtime_send', function() {

$('#employee_table tbody tr').each(function(row, tr) {

your_array.push({
emp_id: $(tr).find('td:eq(0)').text(),
input_val: $(tr).find('input').val()
});

});

});

关于javascript - 如何在jquery中获取动态表数据中文本框的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58334326/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com