Jquery 唯一Div不在特定图标上滑动切换单击
以下是单击图标的html代码:Jquery 唯一Div不在特定图标上滑动切换单击,jquery,html,css,Jquery,Html,Css,以下是单击图标的html代码: <a href="javascript:void(0)" class="stat-item remark" id='id' rel='msg_id' title='Give your Remarks on it'> <i class="fa fa-comments-o icon"></i> </a> 我的项目包括显示几个div(使用php的fetcharrayloop函数从数据库中提取),其中包含不同的内容。但
<a href="javascript:void(0)" class="stat-item remark" id='id' rel='msg_id' title='Give your Remarks on it'>
<i class="fa fa-comments-o icon"></i>
</a>
我的项目包括显示几个div(使用php的
fetcharray
loop函数从数据库中提取),其中包含不同的内容。但是在我能看到的每个div中,div的post-footer类都是相同的,比如icon。我的问题是,当我单击图标时,我可以看到所有名为“post footer”的类都在滑动切换。如何使它们在每次单击图标时独立滑动切换(class=“stat item remark”) 使用data-*
属性,将相关post footer
的data id
存储在链接中,如:
<a href="" class="stat-item remark" data-msg-id="<?php echo $omsg_id;?>" title='Give your Remarks on it'>
<i class="fa fa-comments-o icon"></i>
</a>
<div class="post-footer" id="post-footer-<?php echo $omsg_id;?>">
<p>Loading the list</p>
</div>
希望这有帮助
$(文档).ready(函数(){
$(“.stat item.remark”)。在(“单击”,函数(e){
var post_footer_id=“#post footer-”+$(this.data('id');
$(post_footer_id).css({backgroundColor:'yellow'});
});
});代码>
加载列表
加载列表
加载列表
如果链接和div相邻,请执行next()
:
@PraveenKumar你到底在说什么?每个的rel值应该是多少?我不知道你为什么要用它?没有必要。。如果您想将msg_id
存储在某个地方,最好将其存储在data msg id
属性中。是的,我想为来自dbi的每个invidual帖子附加msg_id。我想精确地处理演示中显示的内容。不幸的是,它不起作用。但我相信您的解决方案将有效地将rel
替换为数据消息id
。。。尝试添加一个警报(post\u footer\u id)
,以确保从链接中获得正确的数据id
。
$(document).ready(function(){
$(".stat-item.remark").on("click", function( e ) {
$(".post-footer").slideToggle();
});
});
<a href="" class="stat-item remark" data-msg-id="<?php echo $omsg_id;?>" title='Give your Remarks on it'>
<i class="fa fa-comments-o icon"></i>
</a>
<div class="post-footer" id="post-footer-<?php echo $omsg_id;?>">
<p>Loading the list</p>
</div>
$(document).ready(function(){
$(".stat-item.remark").on("click", function( e )
{
e.preventDefault();
var post_footer_id = "#post-footer-"+$(this).data('msg-id');
$(post_footer_id).slideToggle();
});
});
<a href="javascript:void(0)" class="stat-item remark" id='<?php echo $omsg_id;?>'rel='<?php echo $msg_id;?>' title='Give your Remarks on it'>
<i class="fa fa-comments-o icon"></i>
</a>
<div class="post-footer" id="post-footer">
<p>Loading the list</p>
</div>
$(document).ready(function(){
$(".stat-item.remark").on("click", function(e) {
$(this).next(".post-footer").slideToggle();
});
});