5

私はjQueryが初めてで、ぼかしがトリガーされたときにテキストボックスの行IDを見つけようとしていますが、これまでのところうまくいきませんでした。

必要なのは、最初のテキストボックスでぼかしイベントがトリガーされたときの#employee_0ようなものだけです。form_data

$("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>
4

3 に答える 3

1

イベント ハンドラー内では、行 ID は次のように使用できます。

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

HTML は合法ではないことに注意してください<td>。.<tr>

代わりに、同じ行にあるすべての入力を検索 (およびシリアル化) しようとしているだけの場合、実際には ID はまったく必要ありません。現在の場所から DOM をトラバースできます。

$("input").blur(function () {
    var form_data = $(this).closest('tr').find('input').serialize();
    $.ajax(...);
});
于 2013-06-13T11:57:04.150 に答える