我所拥有的是以下代码来创建一个 div。
function makeLinkdiv () {
gCurrentBlock = $gBlockDivName + $gBlockPointer;
var idPointer = gCurrentBlock;
var linksBlock = $('<div id ="' + gCurrentBlock + '" class="LinksBlock EditBlock"></div>').appendTo("#canvas");
linksBlock.draggable({containment: "#canvas", scroll: false, grid: [10, 10]}, {cursor: "move", cursorAt: {top: 125, left: 50}});
linksBlock.append('<div class="article_title EditBlock fontCenter fontBold font24">Article Title</div>');
//
// log the div data to the div object
//
var x = gCurrentBlock.css('left');
var y = gCurrentBlock.css('top');
alert ('top is - ' + y + ' left is - ' + x);
divData.items.push({ID: $gBlockPointer, Block: gCurrentBlock, posTop : "450", posLeft : "540" });
//
// increment the block pointer
//
$gBlockPointer = $gBlockPointer + 1;
//
}
发生的事情是我没有得到顶部和左侧的 CSS 属性。实际上,什么也没有发生。我知道我使用变量的方式一定有问题gCurrentBlock
,但我无法弄清楚。