如何在 Javascript 中设置 obj 坐标


var firstBut = document.createElement("button");
    firstBut.id="firstBut";
    firstBut.top=500;
    firstBut.left=500;
    firstBut.textContent="Нажми меня"
    document.body.appendChild(firstBut);

我想为元素设置特定的坐标。我没有找到任何变体如何做到这一点?你能帮我吗?

它应该是这样的:

var firstBut = document.createElement("button");
firstBut.id = "firstBut";
firstBut.style.position = 'absolute';
firstBut.style.top = '500px';
firstBut.style.left = '500px';
firstBut.textContent = "Нажми меня"
document.body.appendChild(firstBut);

相关内容

最新更新