为每个消息区分“回复”按钮有什么好方法? [英] what's a good way to differentiate 'reply' buttons for each message?

查看:175
本文介绍了为每个消息区分“回复”按钮有什么好方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在修改Flask MiniTwit示例来实现类似twitter的消息回复系统,每条消息都有一个回复按钮。我想展开一个新的div来显示回复以及一个输入区域当点击一个指定消息的回复按钮时。但现在我不知道如何在我的jinja模板中定义回复按钮。



目前我的代码如下所示:

 < a href =#data-messageid ={{message._id}}id =reply> 
回复
< / a>

所以如何区分我的jQuery代码中的每个'reply'超链接按钮?

解决方案

 < div class =replymessageid =message {{message._id}}>内容< / DIV> 

$ b $('。reply')。click(function(){
var item = $(this).attr('href');
$ (item).slideToggle(300);
});

在这里演示

基本上你在按钮的href中使用动态id号,然后在相应div的ID中使用。这样,当你点击一个带有href的链接时,打开具有相同ID的div。


I'm modifying Flask MiniTwit example to implement twitter-like message reply system, each message has a 'reply' button. I'd like to expand a new div to display replies as well as an input area When a 'reply' button for a specified message was clicked. but now I don't know how to define the 'reply' button in my jinja template.

current my code is like following:

<a href=# data-messageid="{{message._id}}" id="reply">
Reply
</a>

so how to differentiate each 'reply' hyperlink button in my jQuery code?

解决方案

<div class="replymessage" id="message{{message._id}}">content</div>
<a href="#message{{message._id}}" class="reply">Reply</a>


$('.reply').click( function () {
    var item =  $(this).attr('href');
    $(item).slideToggle(300);
 });

Demo Here

Basically you use the dynamic id number in the href of the button, then in the ID for the corresponding div. This way when you click a link with the href, the div with the same ID opens.

这篇关于为每个消息区分“回复”按钮有什么好方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆