而不能在IE或FF中运行

而不能在IE或FF中运行

本文介绍了toElement似乎只能在Chrome浏览器中运行,而不能在IE或FF中运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下Javascript,它仅在Chrome中有效,我不知道为什么:

I have the following Javascript, and it only works in Chrome, and I can't figure out why:

//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中不起作用.

The problem is that the variables date, timeslot, & tAppt_id are returned as undefined. Again this works in Chrome; but, only in Chrome. DOES NOT work in IE or FF.

我也尝试过使用 e.currentTarget e.relatedTarget 都不起作用.有人可以告诉我我在做什么错吗?

I have also tried using e.currentTarget and e.relatedTarget neither worked. Can someone tell me what I'm doing wrong?

推荐答案

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

Looks like you using jQuery-UI Sortable. In this case you'll get jQuery event object as first parameter to event handler. To get event target element you'll need to use target property:

var element = e.target;

这篇关于toElement似乎只能在Chrome浏览器中运行,而不能在IE或FF中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 13:57