我有这样的跨度 <span class="join-event to-join">join event</span>
.
我使用此功能通过 AJAX 对点击进行操作。
但在成功功能中,我似乎无法向该点击范围添加一个类。
function accept() {
$(".to-join").click(function() {
var id = $(this).attr("data-event");
$.ajax({
type: "post",
url: "../assets/js/ajax/toggle-events.php",
data: { 'id': id },
success: function() {
alert("good job");
$(this).addClass("joined");
},
error: function () {
alert("fail");
}
});
});
}
最佳答案
使用ajax方法的context
选项:
context: this,
context Type: PlainObject This object will be the context of all Ajax-related callbacks. By default, the context is an object that represents the Ajax settings used in the call ($.ajaxSettings merged with the settings passed to $.ajax).
关于javascript - 跨度 addClass 不工作 ajax,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31321730/