js 动态创办div

js 动态创建div
参考一:
<!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=utf-8" />
<title>test</title>
<script>
// Ceeate A div
function createDIV(text,id)
{
    var o = document.getElementById(id);
    var div = document.createElement("div");
    div.id = id+1
div.innerHTML =text;
    o.appendChild(div);
}
function doWhat(id)
{
     createDIV("我是大笨猪,这是DIV里的内容,不能有href",id)
return false;
}
</script>
</head>
<body>
<a href="大笨猪呀" id="benzhu" onclick="return doWhat(this.id)">大笨猪呀</a><br />
需要实现<br />
<a href="大笨猪呀" id="benzhu" onclick="return doWhat(this.id)">大笨猪呀</a>
<div id="benzhu1">我是大笨猪,这是DIV里的内容,不能有href</div>
</body>
</html>

参考二:
js 鼠标经过 弹出菜单 延时隐藏
2010-12-06 16:16
‍<!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 runat="server">
    <title>无标题页</title>

    <script type="text/javascript">
    <!--
    var time;
    function test(){
        var a=document.getElementById("a1");
        var menu=document.getElementById("menu");
        menu.style.display="block";
        var aLeft=a.style.left.substring(0,a.style.left.indexOf("px"));
        menu.style.left=parseInt(aLeft)+10+"px";
        var aTop=a.style.top.substring(0,a.style.top.indexOf("px"));
        menu.style.top=parseInt(aTop)+30+"px";
        clearTimeout(time);
    }
    function test2(){
        var menu=document.getElementById("menu");
        menu.style.display="none";
        clearTimeout(time);
    }
    function test3(){
        time=setTimeout('test2()',1000);
    }
    -->
    </script>
    <style type="text/css">
   #menu{
   width:100px;
   height:200px;
   background-color:#CCCCCC;
   position:absolute;
   display:none;
   }
    </style>
</head>
<body>
<a style="position:relative; left:300px;top:20px;" href="/#" id="a1" onmouseover="test()" onmouseout="test3()">链接</a>
    <div id="menu" onmouseover="test()" onmouseout="test3()">
      <a href="#">收货开单</a>
      <br />
      <a href="/blog/#">装车配送</a>
      <br />
      <a href="/#">客服查询</a>
    </div>
</body>
</html>

参考:
菜单延时加载,并且一秒后消失
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>JavaScript下拉菜单</title>
<style type="text/css">
* {
padding:0;
margin:0;
}
body {
font-family:verdana, sans-serif;
font-size:small;
}
#navigation, #navigation li ul {
list-style-type:none;
}
#navigation {
margin:20px;
}
#navigation li {
float:left;
text-align:center;
position:relative;
}
#navigation li a:link, #navigation li a:visited {
display:block;
text-decoration:none;
color:#000;
width:120px;
height:40px;
line-height:40px;
border:1px solid #fff;
border-width:1px 1px 0 0;
background:#c5dbf2;
padding-left:10px;
}
#navigation li a:hover {
color:#fff;
background:#2687eb;
}
#navigation li ul li a:hover {
color:#fff;
background:#6b839c;
}
#navigation li ul {
display:none;
position:absolute;
top:40px;
left:0;
margin-top:1px;
width:120px;
}
#navigation li ul li ul {
display:none;
position:absolute;
top:0px;
left:130px;
margin-top:0;
margin-left:1px;
width:120px;
}
</style>
<script type="text/javascript">
var timer = {};
function displaySubMenu(li) {
clearTimeout( timer );
var subMenu = li.getElementsByTagName("ul")[0];
subMenu.style.display = "block";
}
function hideSubMenu( li ) {
var subMenu = li.getElementsByTagName("ul")[0];
timer = setTimeout(function(){
subMenu.style.display = "none";
clearTimeout( timer); //接下便便要擦屁屁!
},1000)
}
</script>
</head>
<body>
<ul id="navigation">
<li onmouseover="displaySubMenu(this)" onmouseout="hideSubMenu(this)">
<a pqshow="http://www.02web.com/hublog/">点我吧,囧</a>
<ul>
<li><a href="#">栏目1->菜单1</a></li>
<li><a href="#">栏目1->菜单2</a></li>
<li><a href="#">栏目1->菜单3</a></li>
<li><a href="#">栏目1->菜单4</a></li>
</ul>
</li>
</ul>
</body>
</html>