0

我正在使用信号 R 制作示例聊天应用程序,但我的 keyup 事件已经失效。我使用了克隆这是我的示例代码

//keypress event of textbbox here..
            $(".ChatText").live('keyup', function () {
                if($(".ChatText").val().length > 0)
                {
                alert('test');
                   var messsage_typing=$("#hdnUserName").val() + " is typing...";
                   var strGroupName = $(this).parent().attr('groupname');
                    if (typeof strGroupName !== 'undefined' && strGroupName !== false)
                        chat.server.send($("#hdnUserName").val() + ' : ' + messsage_typing, $(this).parent().attr('groupname'),"1");

                }
            });
            //end of keypress

这是我添加消息的代码

 chat.client.addMessage = function (message, groupName,recievername,imagetag,Istypingmessage) {

            if ($('div[groupname=' + groupName + ']').length == 0) {
                var chatWindow = $("#divChatWindow").clone(true);
                //also tried this not working 
                //var chatWindow = $("#divChatWindow").clone(true,true);
                $(chatWindow).css('display', 'block');
                $(chatWindow).attr('groupname', groupName);

                $("#chatContainer").append(chatWindow);
                //buggy code do not delete..
                //remove all previous li
                $('div[groupname=' + groupName + ']').find('ul li').remove();
                //replace header tag with new name
                $('div[groupname=' + groupName + ']').find('a').html(recievername);

                $("#chatContainer").draggable();
                $("#chatContainer").css('cursor','move');
            }

请帮我在这里绑定我的keyup事件..谢谢

4

1 回答 1

1

尝试克隆元素的深层副本

var clone = $('.hello').clone(true);

http://api.jquery.com/clone/#clone-withDataAndEvents

于 2013-05-01T13:48:46.923 回答