我有一个 HTML 表单,我需要获取最近的 tbody
中所有输入的值(页面上会有多个 tbody
)。我想序列化这些值并发送给 ajax。
到目前为止我的代码是:
$(document).on('change', '.disguise', function (e) {
//var params = $('').find('input').serialize(); // get all inputs from clicked row
$.ajax({
type: 'post',
dataType: 'json',
url: '/calculateHours',
data: params,
success: function (response) {
alert('Done...');
}
});
});
最佳答案
I need to get the values of all inputs inside the closest tbody
使用closest()
和find()
var params = $(this).closest('tbody').find('input').serialize();
要选择所有表单元素,请使用 :input选择器
var params = $(this).closest('tbody').find(':input').serialize();
关于jquery - 我怎样才能从最近的 tbody 获得所有输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33523975/