针对从PHP传递的特定元素ID


Targeting specific element ID that is passed from PHP

我目前每页列出10个项目,问题是当调用此函数时,它只针对第一个(最新的(元素,而对其余元素不做任何操作。我的问题是:我将如何针对每个人<span id="report-text"></span>其中CCD_ 2元素属于由PHP给出的相同的唯一id CCD_。

这是我对目标元素的Jquery代码

$('#report').hover(function(){
    $('#report-text').show();
},function(){
$('#report-text').hide();
});

HTML代码如下:

<div class="vote_wrap" id="<?php echo $row->id;?>">
<span id="report-text">Report Inappropriate Content</span>
<i class="fa fa-exclamation" id="report"></i>
</div>

您可以通过实现正确的选择器来实现。。在评论中使用类作为建议。。

按以下操作-

JS

 $('.report').hover(function(){
        $(this).prev('.report-text').show();
    },function(){
    $(this).prev('.report-text').hide();
    });

HTML

<div class="vote_wrap" id="<?php echo $row->id;?>">
<span class="report-text">Report Inappropriate Content</span>
<i class="fa fa-exclamation" class="report"></i>
</div>

每个id值在文档中只能使用一次。如果多个元素被分配了相同的ID,则使用该ID的查询将只选择DOM中第一个匹配的元素

将您的ID更改为Class