简体   繁体   English

Onclick js函数消失

[英]Onclick js function disappearing

Ok here's the problem: I have a sidebar where all the friends are and their online status. 好的,这是问题所在:我有一个侧边栏,所有朋友都在哪里,以及他们的在线状态。 If you click on a friend, they appear at the footer and a chat box appears at the bottom of the screen. 如果您单击一个朋友,则他们会出现在页脚中,并且聊天框会出现在屏幕底部。

On the top of the chat box there are 2 buttons that have images inside. 在聊天框的顶部,有2个按钮,其中包含图像。 One a minimize, the other a close button. 一个最小化,另一个关闭按钮。 When the minimize button is clicked, the chat box is removed but they stay in the footer. 单击最小化按钮时,聊天框将被删除,但它们将保留在页脚中。 If the close button is clicked the chat box is removed and they are removed from the footer. 如果单击关闭按钮,则聊天框将被删除,并且它们将从页脚中删除。

This all works fine and dandy but when I click the minimize button, <button onclick='minimize()'>...</button> and reclick the friend, the close button's onclick is empty and doesn't work... Also I tried using jQuery's .click function but it didn't do anything. 这一切都很好,但当我单击最小按钮, <button onclick='minimize()'>...</button>并重新单击朋友时,关闭按钮的onclick为空并且不起作用...我也尝试使用jQuery的.click函数,但是它什么也没做。 Alright, i got another computer...here's my jquery code: 好吧,我有另一台电脑...这是我的jquery代码:

function minimizefcc(){
   var current_friend = $("#fcc_container header span").text(); //get current chat window username
   $("li.fcc_li"+current_friend+"_username").attr('data-activeconnection', 'false');
   $("li.friend_li."+current_friend+"_username").attr('data-activeconnection', 'false');
   $("#fcc_container").remove();//get rid of chat box(fcc_container = friend chat    container)
}

function closefcc(){
   var current_friend = $("#fcc_container header span").text(); //get current chat window username
   $("li.fcc_li"+current_friend+"_username").attr('data-activeconnection', 'false');
   $("li.friend_li."+current_friend+"_username").attr('data-activeconnection', 'false');
   $("#fcc_container").remove();//get rid of chat box(fcc_container = friend chat    container)
   $("li.fcc_li."+current_friend+"_username").remove();
   $("li.friend_li."+current_friend+"_username").attr('data-fcopen', 'false');
}

//heres the main code

$(document).ready(function(){
   var friendli = $("li.friend_li");
   var footer = $("#footer");
   var fccli = $(".fcc_li");
   friendli.click(function(){
      var username  = $(this).attr("data-fcusername");
      var open = $(this).attr('data-fcopen');
      var active = $(this).attr('data-activeconnection');
      if(open === 'false' && active === 'false'){
         //friend isn't in footer and isn't in chat box
         $(this).attr('data-fcopen', 'true');
         $(this).attr('data-activeconnection', 'true');
         $("#footer #fcc_ul").append("<li class='fcc_li "+username+"_username' data-   activeconnection='true' data-fcopen='true' data-fcusername='"+username+"'>"+username+"<img   src='you dont need the source' title='status' class='status_img "+username+"_status'/></div>");
         minimizefcc();
         $("body").append("<div id='fcc_container'><header id='fcc_header'><span>"+username+"</span>"+
"<button id='fcc_minimizeButton' onclick='minimizefcc()'><img src='you dont need source...' title='minimize'/></button>"+
"<section id='fcc_messageContainer'></section><textarea id='fcc_input'></textarea></div>");
      }

      if(open === 'true'&& active === 'false'){
         //friend is in footer but not in chatbox
         $(this).attr('data-activeconnection', 'true')
         minimizefcc();
         $("body").append("<div id='fcc_container'><header id='fcc_header'>" +
         "<button id='fcc_minimizeButton' onclick='minimizefcc()'><img src='you dont need source...' title='minimize'/></button>"+
         "<section id='fcc_messageContainer'></section><textarea id='fcc_input'></textarea></div>"):
         $("li.fcc_li."+username+"_username").attr('data-activeconnection', true');
   });
});

好的,我想提出一点错误,因为这是一个非常愚蠢的错误……在第二个中,如果我在其中添加了按钮,却忘记添加onclick ='closefcc()',那简直就是傻瓜,我的坏蛋。

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

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