问题描述
我在页面中动态创建了一个div.
代码如下:-
-------
函数CreateDiv()
{
var codeDiv = document.createElement(''div'');
codeDiv.id =``codeDiv'';
codeDiv.innerHTML ="JavaScript";
codeDiv.style.position =相对";
codeDiv.style.borderStyle =固体";
codeDiv.style.borderWidth ="1px";
codeDiv.style.borderColor =红色";
codeDiv.style.height ="250px";
codeDiv.style.width ="400px";
codeDiv.style.left ="150px";
codeDiv.style.top ="50px";
codeDiv.style.backgroundColor =``灰色'';
document.body.appendChild(codeDiv);
}
我想在动态创建的div(''codeDiv'')上添加
I dynamically created a div in my page.
The code is below:-
-------
function CreateDiv()
{
var codeDiv = document.createElement(''div'');
codeDiv.id = ''codeDiv'';
codeDiv.innerHTML = "JavaScript";
codeDiv.style.position = "relative";
codeDiv.style.borderStyle = "solid";
codeDiv.style.borderWidth = "1px";
codeDiv.style.borderColor = "Red";
codeDiv.style.height = "250px";
codeDiv.style.width = "400px";
codeDiv.style.left = "150px";
codeDiv.style.top = "50px";
codeDiv.style.backgroundColor = ''gray'';
document.body.appendChild(codeDiv);
}
I want to add the
推荐答案
newTag=document.createElement('< new tag >');
>设置新标签的样式属性以重新放置它
> set style property of new tag to re-position it
newTag.style.position="absolute";
newTag.style.left="0px";
newTag.style.top="-15px";
>将其附加在codeDiv元素中
> append it in codeDiv element
codeDiv.appendChild(newTag);
这篇关于在动态创建的div上创建标签.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!