资料
表格
制度
合同
管理
职场
经营
创业
范文
总结
计划
作文
文章
美文
词句
教程
模板
图片
字体
图标
办公
人事
财务
生产
管理资源吧首页
>>>
教程
>>>
编程
>>>
JavaScript教程
>>>
js 动态创建 html元素
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title> js学习之动态创建html元素</title> <style><!-- body{margin:0;padding:0;} .sky{background:#000;width:1000;height:500px; position:relative;} #s{ background:#FFF; width:1px; height:1px; overflow:hidden; position:absolute;} --></style><style bogus="1">body{margin:0;padding:0;} .sky{background:#000;width:1000;height:500px; position:relative;} #s{ background:#FFF; width:1px; height:1px; overflow:hidden; position:absolute;}</style> </head> <body> <div class="sky" id="sky"></div> <button id="creatstar" onclick="creatstars()">没事造星星玩</button> <img src="/_New/_cj/myeditor/sysimage/space.gif" class="ewebeditor__script" _ewebeditor_fake_tag="script" _ewebeditor_fake_value="%3Cscript%20type%3D%22text%2Fjavascript%22%3E%3C!--%20%0D%0Afunction%20%24(id)%7B%20return%20document.getElementById(id)%3B%7D%3B%20%0D%0A%0D%0Afunction%20creatstars()%7B%20%0D%0Avar%20star%20%3D%20document.createElement(%22div%22)%3B%20%0D%0Astar.id%20%3D%20%22s%22%3B%20%0D%0Avar%20posX%20%3D%20Math.floor(Math.random(star.style.top)*400%2B100)%3B%20%0D%0Avar%20posY%20%3D%20Math.floor(Math.random(star.style.left)*1000%2B1)%3B%20%0D%0A%24(%22sky%22).appendChild(star)%3B%20%0D%0Astar.style.top%20%3D%20posX%20%2B%20%22px%22%3B%20%0D%0Astar.style.left%20%3D%20posY%20%2B%20%22px%22%3B%20%0D%0A%7D%20%0D%0A%2F%2F%20--%3E%3C%2Fscript%3E"> </body> </html>
[Ctrl+A 全选 注:
如需引入外部Js需刷新才能执行
]
教程首页
更多教程