$(document).ready(function () {
var user = 1;
$("a.like").on("click", function () {
var article = $(this).attr('data-article');
$.ajax({
type: "POST",
url: "WebService.asmx/Like",
data: "{ 'user': '" + user + "', 'article': '" + article + "' }",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
if(msg.d == 1)
{
$(".like[data-article='" + article + "']").fadeOut(700).addClass('unlike').removeClass('like').stop().text('Unlike').fadeIn(700);
}
},
failure: function (msg) {
alert(msg.d);
}
});
});
$("a.unlike").on("click", function () {
var article = $(this).attr('data-article');
$.ajax({
type: "POST",
url: "WebService.asmx/Unlike",
data: "{ 'user': '" + user + "', 'article': '" + article + "' }",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
if(msg.d == 1)
{
$(".unlike[data-article='" + article + "']").fadeOut(700).addClass('like').removeClass('unlike').stop().text('Like').fadeIn(700);
}
},
failure: function (msg) {
alert(msg.d);
}
});
});
});
当我单击具有类的链接时,它工作正常,当我单击具有类的链接时,它与此不同。但是,当我单击同一链接两次时它不起作用!当我在互联网上搜索时,我发现我必须使用 live 而不是 click,但是 live 在 1.8 版本上已被弃用。我怎样才能使这种火灾多次?