简体   繁体   English

打开类似于Twitter的div onclick

[英]Open a div onclick similar to twitter

I am stuck here and really could use some help. 我被困在这里,确实可以使用一些帮助。 I am trying to create something similar to twitter now i am stuck at the part of when click on message get replies to this message. 我正在尝试创建类似于twitter的东西,现在我被困在单击消息时获得对此消息的答复。 This is what i have done till now any help please 这是我到目前为止所做的任何帮助

This function to get the last reply for this message. 此功能获取此消息的最后答复。

function getlastReply()
{
   var reply_id;
var msg_id = $("#flag").val();
$.ajax({ 
    type: "post",
    url: "includes/getLastReplyID.php",
    data: "MsgID="+msg_id,
    success: function(reply_id)
    {
      $("#last_reply_id").val(reply_id);
    }
  });
 }

This function to get the replies and add it to a div 此函数获取答复并将其添加到div

function getReplies(msg_id)
 {

//when clicked show another div 
    var getID   =  msg_id;

    var this_reply = $("#last_reply_id").val();

    /// check if div is already open
    var flag = $('#flag').val();

    // check the flag of msg id, if equal, close it, and set flag to zero 
    if(flag == getID) // hide it
    {
        $('#content2').css("z-index","-1");
        $('#content2').animate( {
          left: '250px',
        },250);

        // set flag to 0
        $('#flag').val(0);
    }
    else // show it
    {

        // check if another msg is opened , if yes, close it first
        if(flag > 0) // hide it
        {
            $('#content2').css("z-index","-1");
            $('#content2').animate( {
              left: '250px',
            },250);
        }
        // end of check if another msg is opened , if yes, close it first


        $('#content2').show();
        $('#content2').animate( {
          left: '730px',
        },250, function() {
            $('#content2').css("z-index","1");
        });

  $.ajax({
  type: "post",
  url: "includes/getReplies.php",
  data: "Msg_ID="+msg_id+"&reply_id="+this_reply,
  dataType: "xml",
  success: function(data)
  {
     $(data).find("message").each(function() {
     var msg_id = $(this).find("msg_id").text();
     var user_id = $(this).find("user_id").text();
     var msg = $(this).find("msg").text();
     var time = $(this).find("date_time").text(); 
     var user_name = $(this).find("user_name").text(); 

     var html  = '<div media="true" class="stream-item " html -item-type="tweet" id="'+msg_id+'">';
     html  += '<div class="more" onclick="getReplies('+msg_id+')">»</div>';
     html  += '<input type="hidden" value=></input>';
     html  += '<div class="stream-item-content tweet stream-tweet " html -user-id="1921671">';
     html  += '<div class="tweet-content">';
     html  += '<div class="tweet-row">';
     html  += '<span class="tweet-user-name">';
     html  += '<a class="tweet-screen-name user-profile-link" html>'+user_name+'</a>';
     html  += '<span class="tweet-full-name"></span></span>';
     html  += '<div class="tweet-corner">';
     html  += '<div class="tweet-meta">';
     html  += '<span class="icons">';
     html  += '<div class="extra-icons">';
     html  += '<span class="inlinemedia-icons"></span>';
     html  += '</div>';  
     html  += '</span>';
     html  += '</div>';
     html  += '</div>';
     html  += '<div class="tweet-row">'+msg+'</div>';
     html  += '<div class="tweet-row">';
     html  += '<a class="tweet-timestamp" title='+time+'><span class="_timestamp" html -time="1302776815000" html -long-form="true">'+time+'</span></a>';
     html  += '<span>';
     html  += '</span>';
     html  += '<span >';
     html  += '</span><b> Msg ID '+msg_id+'</b>';
     html  += '</div><div class="tweet-row">';          
     html  += '</div>';
     html  += '</div>';
     html  += '</div>';
     $("#reply_msg_div").prepend(html);
     $("#last_reply_id").val(0);
     $("#this_msg").val(0);
    });
  }
});
        // set flag to msg id
        $('#flag').val(getID);
    }

Now the problem is that when i click a message ok it gets the replies but when click on a new one it just appends the messages to old messages. 现在的问题是,当我单击确定时,它会收到答复,但是单击新消息时,它将消息追加到旧消息中。 So there may be something wrong i am doing i am not sure. 所以我不确定我在做错什么。

Thanks 谢谢

I had a similar issue using prototype.js, where I had to clear the div before filling it, from an ajax call. 我在使用prototype.js时遇到了类似的问题,我必须从ajax调用中清除div,然后再填充它。

try and empty the div first: 尝试先清空div:

$("#reply_msg_div").empty();
$("#reply_msg_div").prepend(html);

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

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