gpt4 book ai didi

html - 通过ajax插入html时设置html div位置的正确方法

转载 作者:太空宇宙 更新时间:2023-11-04 16:25:31 24 4
gpt4 key购买 nike

我正在用 javascript 动态构建 html。然后这将被插入到一个元素中。在我创建的 html 中设置顶部、左侧、宽度和高度属性的正确方法是什么。我目前的技术适用于 IE,但不适用于 Chrome 或 Safari。这就是我目前的做法(控制组是一个包含我的属性的对象):

html += '<div id="' + controlgroup.id + '" class="controlgroup ui-widget-content"';
html += ' style="{';
html += 'top:' + controlgroup.top + '; left:' + controlgroup.left + ';';
html += 'width:' + controlgroup.width + '; height:' + controlgroup.height + ';';
html += '}">';
html += 'cg:' + controlgroup.id + ' ' + controlgroup.left + ',' + controlgroup.top;
html += '</div>';

然后我这样做:

$('#formcontainer').html(html);

我需要能够指定精确的坐标,所以我不能在这里使用“预定义”的 css 类。非常感谢。

最佳答案

1) 您需要使用 leftrightheightwidth 附有 px 的值。因此,不要将 width:50; 设置为 width:50px;

2) 您需要将 position:relative; 添加到您的样式中。

3) 不需要 {} 括号

工作演示: http://jsfiddle.net/Jaybles/6fbvT/2/

关于html - 通过ajax插入html时设置html div位置的正确方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5636548/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com