如何使用jquery获取父id的值

时间:2022-11-27 11:29:29

This is the html i am using

这是我正在使用的HTML

    <tr>
    <td>No.</td>
    <td id="2" class="editable">data1</td>
    <td id="2" class="editable">data2</td>
    <td>Usage Left</td>
    </tr>
    <!-- Multiple rows with different ids --> 

and this is my javascript

这是我的javascript

    $(function(){

    $('.editable').editable({onSubmit:Update});

    function Update(){
        var id = $(this).parent('td').attr('id');
        var title = $(this).text();

        $.ajax({
        type: 'post',
        url: 'update.php',
        data: 'title=' + title + '&id=' + id,

        success: function(response) {             
            $('#response').fadeIn('1000').empty().append(response);
        }
        });

    }
    });

I want to get the value of the ids of class editable, this is a inline edit plugin i am using i am able to collect the data1 and data2 values but for id i am getting undefined.

我想得到类可编辑的id的值,这是一个内联编辑插件我正在使用我能够收集data1和data2值,但对于id我未定义。

What is wrong with my code.

我的代码有什么问题。

Thank You.

1 个解决方案

#1


Shouldn't it be just $(this).attr('id')?

不应该只是$(this).attr('id')?

You are attaching the event to td. So this inside the event handler refers to the td itself.

您正在将事件附加到td。所以这个事件处理程序内部引用了td本身。

#1


Shouldn't it be just $(this).attr('id')?

不应该只是$(this).attr('id')?

You are attaching the event to td. So this inside the event handler refers to the td itself.

您正在将事件附加到td。所以这个事件处理程序内部引用了td本身。