2014-03-28 35 views
3

我有以下的JavaScript来的工作,并且只在Chrome的工作,而且我想不通为什么:toElement似乎只在Chrome,IE不FF或

//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.currentTargete.relatedTarget都没有工作。有人能告诉我我做错了什么吗?

回答

5

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

var element = e.target; 
+0

这就是它的人!感谢您的帮助! – BlackHatSamurai

+0

我刚刚意识到,你给我的答案获得了原点元素,我将如何获得项目被删除的元素? – BlackHatSamurai

+0

根据[documentation](http://api.jqueryui.com/sortable/#event-stop)它将来自处理程序的'ui.item'第二个参数'stop:function(e,ui){'。 –

相关问题