我想动态创建一个文本框,然后动态定位文本框。我已经能够毫无问题地动态创建文本框,但我还不能确定如何定位它。有什么建议吗?
发布于 2009-09-30 15:17:15
var box = document.createElement('input'); // creates the element
box.style.position = 'absolute'; // position it
box.style.left = '100px';
box.style.top = '100px';
document.body.appendChild(box); // add it as last child of body elemnt
如果要将其添加到文档层次结构中的其他位置,则必须使用getElementById找到父元素并使用该元素的appendChild函数。
发布于 2009-09-30 13:40:28
设置“顶部”和“左侧”位置?您可能还需要将"position“属性设置为”相对“或”绝对“,具体取决于您要执行的操作。
发布于 2009-09-30 13:40:53
位置在哪里?
您是否尝试在某个特定点或其他元素中进行定位?尝试在textbox类的CSS中使用position: absolute,或者在DOM中的对象上使用style属性。
https://stackoverflow.com/questions/1498192
复制相似问题