当用户点击取消关注按钮,并成功结束请求,我改变了我的按钮是一个按钮,它仍然在听取消跟踪功能!看到下面的代码jquery点击事件重复
$(document).ready(function() {
$("button[data-follow]").on("click",function(){
var id = $(this).attr("data-follow");
$.ajax({
data: {followid : id } ,
url:"follow.php",
type:"POST",
datatype: "json",
success: function(data){
alert(data);
$(this).css({"background" : "green"});
}
});});
$("button[data-unfollow]").on("click",function(){
var there = $(this);
var id = there.attr("data-unfollow");
$.ajax({
data: {followid : id } ,
url:"unfollow.php",
type:"POST",
success: function(data){
alert(data);
there.text("follow");
there.attr("data-follow","1234");
}
});
});
});
当我点击按照它应该发送请求跟随url,但它仍然发送到取消关注!
提供您的html也 – 2014-12-05 12:53:53
button取消关注 – 2014-12-05 12:56:20
嗯,通常与委派的事件绑定,你希望父母与参数中的选择器。即$(“#your parent div”)。on(“button [data-follow]”,“click”,function ...等 – 2014-12-05 12:57:01