您好,我正在使用这样的 ajax 调用绑定我的聊天好友列表
$.ajax({
type: "POST",
url: "/getdata.asmx/GetUserInfo",
data: "{'Id':'" + gorge + "' }",
contentType: "application/json; charset=utf-8",
dataType: "json",
error: function (XMLHttpRequest, textStatus, errorThrown) { alert(errorThrown); },
success: function (xml) {
//alert('success');
$('#frndcontact li').remove();
// $("#frndcontact").innerhtml("");
// DivMainContainer
var obj = jQuery.parseJSON(xml.d);
// alert(data);
if (obj.length > 0) {
for (var i = 0; i < obj.length; i++) {
// var name = obj[i].name;
var objname = "'" + obj[i].name + "'";
//alert(name);
var H = '<li style="font-size:11px;font-family:\'lucida grande\',tahoma,verdana,arial,sans-serif;">' +
'<img alt="" height="18px" width="18px" id="test-' + obj[i].friendid + '" src="Images/offline.png" />' +
'<a class="UserItem" id="test-' + obj[i].friendid + '" >' + obj[i].name + '</a>' +
'</li>'
$("#frndcontact").append(H);
}
}
}
});
然后下面是我的信号 R 代码
$.connection.hub.qs = "Id=" + gorge;
var chat = $.connection.chat3Hub;
chat.client.foo = function () { };
$.connection.hub.start(function () {
// chat.server.OnConnected();
// chat.server.getAllOnlineStatus();
});
chat.client.disconnect = function (connectionId, userList) {
$(userList).each(function (index, obj) {
$("#test-" + obj).attr('src', 'images/offline.png');
$("#test-" + obj).next('.UserItem').removeClass('online');
});
};
chat.client.disconnectuservialogout = function (connectionId, userList) {
$(userList).each(function (index, obj) {
$("#test-" + obj).attr('src', 'images/offline.png');
$("#test-" + obj).next('.UserItem').removeClass('online');
});
};
chat.client.joined = function (connectionId, userList) {
$(userList).each(function (index, obj) {
$("#test-" + obj).attr('src', 'images/online.png');
$("#test-" + obj).next('.UserItem').addClass('online');
});
};
$('.logout').click(function () {
chat.server.disconectonlogout();
});
**//THIS CODE IS NOT WORKING DONT KNOW WHY**
**$('.UserItem').click(function () {
var chatWindow = $("#divChatWindow").clone(true);
$("#chatContainer").append(chatWindow);
});**
// $.connection.hub.server.connected = function () { }
});
但是当我执行下面的代码时,我将事件绑定到具有类 Useritem 的锚标记..但是当我在 Firefox 调试器的 javascript 中放置断点时,它不会到来。所以我无法绑定锚标记的点击事件该怎么办..请帮帮我