toElement似乎只适用于Chrome,而不是IE或FF

Bla*_*rai 3 jquery internet-explorer google-chrome jquery-ui

我有以下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(); 
                }
            }
        });
    }

});
Run Code Online (Sandbox Code Playgroud)

问题是变量date,timeslot,和tAppt_id作为返回undefined.这又适用于Chrome; 但是,仅限Chrome.不能在IE或FF中工作.

我也尝试使用e.currentTarget,e.relatedTarget但都没有工作.有人能告诉我我做错了什么吗?

Iva*_*uev 5

看起来你使用jQuery-UI Sortable.在这种情况下,您将获得jQuery 事件对象作为事件处理程序的第一个参数.要获取事件目标元素,您需要使用target属性:

var element = e.target;  
Run Code Online (Sandbox Code Playgroud)