Skip to main content
 首页 » 编程设计

jquery之我正在尝试从帖子中获取数组的值

2026年07月28日4davidwang456

我是 jQuery 新手,我试图在触发模糊时找到文本框的行 ID,但到目前为止我还无法使其工作。

当我的第一个文本框上触发模糊事件时,我需要的只是 form_data 中的 #employee_0 之类的内容。

$("input").blur(function () { 
 
    $('input').each(function (index, value) { 
 
        var form_data = $("#employee_" + index).find('input').serialize(); 
        $.ajax({ 
            url: "<?php echo site_url("HomeController / calculate_time_lap "); ?>", 
            type: 'POST', 
            data: form_data, 
            success: function (result) { 
                $('input').closest('tr').find('.TextBox3').val(result); 
            } 
        }); 
        return false; 
    }); 

这是我的查看页面:

<tr id="employee_0"><input type ="textbox"></tr> 
<tr id="employee_1"><input type ="textbox"></tr> 
<tr id="employee_2"><input type ="textbox"></tr> 
<tr id="employee_3"><input type ="textbox"></tr> 
<tr id="employee_4"><input type ="textbox"></tr> 

请您参考如下方法:

在事件处理程序中,行 ID 将如下所示:

$(this).closest('tr').attr('id'); 

请注意,您的 HTML 不合法 - 您需要 <td> <tr> 内的元素.

如果您只是想查找(并序列化)同一行中的所有输入,则实际上根本不需要 ID,您只需从所在位置遍历 DOM :

$("input").blur(function () { 
    var form_data = $(this).closest('tr').find('input').serialize(); 
    $.ajax(...); 
});