求救,关于createElement创建div的问题?在线

cleanduo 2005-01-24 01:56:17
<html>
<head>
<SCRIPT LANGUAGE=javascript>
function bbb()
{
var str = document.createElement("div");
str.id = "asdf";
str.style.position = "absolute";
str.style.setAttribute("left","1px");
str.style.setAttribute("top","1px");
str.style.setAttribute("width","100px");
str.style.setAttribute("height","100px");
str.style.setAttribute("border","1 solid #000000");
//str.style.setAttribute("background-color","#000000");
//str.style.setAttribute("layer-background-color","#000000");
str.style.setAttribute("z-index","1");
document.body.appendChild(str);
}
</SCRIPT>
</head>
<body>
<input type=button value=test onclick="bbb()">
</body>
</html>

我用background-color和layer-background-color都没有任何反应,怎么办?
...全文
643 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
cleanduo 2005-01-24
  • 打赏
  • 举报
回复
it's ok
vivianfdlpw 2005-01-24
  • 打赏
  • 举报
回复
var d=document.getElementById("asdf");
document.body.removeChild(d);
meizz 2005-01-24
  • 打赏
  • 举报
回复
<html>
<head>
<SCRIPT LANGUAGE=javascript>
function bbb()
{
var str = document.createElement("div");
str.id = "asdf";
with(str.style)
{
position = "absolute";
left = "100px";
top = "100px";
width = "100px";
height = "100px";
border = "1 solid #000000";
backgroundColor = "#000000";
zIndex = "1";
}
document.body.appendChild(str);
}
</SCRIPT>
</head>
<body>
<input type=button value=test onclick="bbb()">
<input type=button value=del onclick="document.all.asdf.removeNode(true)">
</body>
</html>
cleanduo 2005-01-24
  • 打赏
  • 举报
回复
谢谢,我还想问个问题,
就是怎么把用createElement创建的div删掉呢(通过写脚本)?
JK_10000 2005-01-24
  • 打赏
  • 举报
回复

str.style.setAttribute("background-color","#000000");

--->>>>

str.style.setAttribute("backgroundColor","#000000");
vivianfdlpw 2005-01-24
  • 打赏
  • 举报
回复
str.style.setAttribute("backgroundColor","#000000");

87,907

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧