标签:_id xhr parse 鼠标 data addclass 登陆 源码 attr
/*点赞功能实现*/ $(‘div.thumbup‘).unbind(‘click‘).bind(‘click‘ ,function(){ var img = $(‘img‘, $(this)); var data = img.attr(‘data‘); var cookie_key = ‘tz100_worth_‘ + data; $.ajax({ type: "POST", contentType: "application/json", url: "/item/worth/", data: {"item_id": data}, success: function(msg) { if(msg.result == ‘exist‘) { alert(‘已投票!‘); } else if(msg.result == ‘unlogin‘) { alert("先登陆,才能投票"); } else { img.next().text(parseInt(img.next().text()) + 1); $.cookie(cookie_key, 1, { expires: 365, path: ‘/‘, domain:‘www.tz100.com‘ }); } }, error: function(msg) {} }); }); /*小规模的鼠标经过展示对应图片,当鼠标移过时,取到对于图片的路径,更换图片显示区图片路径即可*/ $("div.thumb-list img").mouseover(function(){ $("div.thumb-list li").removeClass(‘cur‘); var $li = $(this).parent().parent(); $li.addClass(‘cur‘); var curImg = $(this).attr("data-src"); $("#cell_" + $li.attr(‘data‘) + ‘ div.gallery div.pic-box img‘).attr("src", curImg); }); /*收藏功能*/ $("a.like_big").unbind(‘click‘).bind(‘click‘, function(){ var link = $(this); if(‘‘.length == 0) { link.text(‘先登录才能收藏哦~‘); } $.ajax({ type: "POST", contentType: "application/json", url: "/item/favorite/", data: {"item_id": $(this).attr(‘data‘)}, beforeSend: function(xhr) { xhr.setRequestHeader("X-CSRFToken", $.cookie(‘csrftoken‘)); }, success: function(msg) { if(msg.result == "success") { $(link).text(‘已收藏~‘); } else if(msg.result == "exist") { $(".favorite_num", link).text(‘过了哦~‘); } }, error: function(msg) {} }); });
标签:_id xhr parse 鼠标 data addclass 登陆 源码 attr
原文地址:http://www.cnblogs.com/chenyongyang/p/7747273.html