将注意力转移到第二个console.log,即我周围的console.logs工作正常并打印last_pos,其中有两个名为“top”和“top”的int属性,我不断得到“错误:last_pos未定义”剩下”。无论我是否尝试点符号或括号表示,我都会收到错误。这样的矛盾怎么会发生?
var last_dropped_id = '';
var last_pos = '';
$( ".drop-area" ).droppable({
tolerance: "touch",
drop: function( event, ui ) {
var valMy = "center";
var valAt = "top center";
if(last_dropped_id != undefined){
var last_pos = $(last_dropped_id).position();
console.log(last_pos);
console.log(last_pos['left']);
console.log("WTF");
console.log(last_pos);
//valMy+= "+" + last_pos;
// valAt+= "+" + last_pos.top;
}
var $this = $(this);
ui.draggable.position({
my: valMy,
at: valAt,
of: $this,
using: function(pos) {
$(this).animate(pos, 400, "linear");
},
});
last_dropped_id = '#' + ui.draggable.attr('id');
console.log(last_dropped_id);
}
});