简体   繁体   English

jQuery从点击的div获取ID

[英]Jquery get id from clicked div

I have a html structure like this 我有这样的html结构

 <div class='mydiv' id='89'>hello</div>
 <div class='mydiv' id='123'>hihihi</div>

And my jQuery is currently like this 我的jQuery当前是这样的

$('.mydiv').click(function(){
$.ajax({
     type: "POST",
     url: 'getdata.php',
     data: { uid: "UNKNOWN" }
     success: function(data) {
     $('#o').html(data);
     $('#o').fadeIn("fast");
    }
    });
    });

What i need is to fill in the UNKNOWN in the data for jQuery with the id from the div that was clicked 我需要用单击的div中的ID填充jQuery数据中的UNKNOWN

Thanks, 谢谢,

You could use this.id to get the id. 您可以使用this.id来获取ID。

$('.mydiv').click(function () {
    $.ajax({
        type: "POST",
        url: 'getdata.php',
        data: {
            uid: this.id
        },
        success: function (data) {
            $('#o').html(data);
            $('#o').fadeIn("fast");
        }
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM