我有以下 Javascript,它只适用于 Chrome,我不明白为什么:
//makes appointments draggable
$("._ts").sortable({
connectWith: "._ts",
revert: "true",
cancel: ".new_appt",
stop: function(e){
var element = e.toElement;
var date = $(element).parents('.route_container').find('.date h2').html();
var timeslot = $(element).parents('.timeslot').attr('id');
var tAppt_id = $(element).attr('id');
console.log("Date:."+date);
console.log("time:."+timeslot);
console.log("route:."+tAppt_id);
$.ajax({
type: "post",
dataType: "json",
url: ajaxurl,
data:{action: "update_appointments", date: date, timeslot: timeslot, appt_id: tAppt_id},
success: function(response){
if(response.type == "success"){
console.log("Update appointment worked.");
console.log("Date:."+response.date);
console.log("time:."+response.timeslot);
console.log("route:."+response.timeslot);
$(this).parents('.delete_appt').hide();
}
}
});
}
});
问题是变量date
, timeslot
, & tAppt_id
返回为undefined
。这同样适用于 Chrome;但是,仅限于 Chrome。不适用于 IE 或 FF。
我也尝试过使用e.currentTarget
and e.relatedTarget
两者都不起作用。有人可以告诉我我做错了什么吗?
看起来您正在使用 jQuery-UI Sortable。在这种情况下你会得到 jQueryevent http://api.jquery.com/category/events/event-object/对象作为事件处理程序的第一个参数。要获取事件目标元素,您需要使用target http://api.jquery.com/event.target/财产:
var element = e.target;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)