$(function() {
var xpos = $(`#${currentid}`).position();
console.log(xpos.top);
var sPositions = localStorage.positions || "{}",
positions = JSON.parse(sPositions);
$.each(positions, function(id, pos) {
$("#" + id).css(pos);
console.log("it saves");
})
$(`#${currentid}`).draggable({
containment: "#body1",
scroll: false,
stop: function(event, ui) {
positions[this.id] = ui.position;
localStorage.positions = JSON.stringify(positions);
console.log("it loads");
}
});
});
在这种情况下,我必须遍历每个元素,但仍然无法正常工作,请帮助