问题
I am trying to get the position of a specific div when it is dropped. With some help i have put together the code bellow. I added in the last bit to try and get the specific values but it simply returns [object Object] instead of something like [0,0] or [0,120].
So the question is how do i get the actual values from the array?
Here is a jsFiddle
$(function() {
$('.AppList').droppable({
accept: ".App",
tolerance: 'fit',
drop: function(event, ui) {
var apps = $(".App"),
positions = [];
$.each(apps, function (index, app) {
var positionInfo = $(app).position();
positions.push(positionInfo);
});
var Time = positions.slice(0,1);
var x=document.getElementById("posThis");
x.innerHTML=Time;
console.log(positions);
}
});
});
回答1:
The problem here is that positionInfo
is an object, not an array. Time
is an array with one such object inside.
I believe you want something like this:
var Time = positions[0];
var x=document.getElementById("posThis");
x.innerHTML= '[' + Time.left + ',' + Time.top + ']';
来源:https://stackoverflow.com/questions/16245137/array-slice-returning-object-object-instead-of-value