日期:2014-05-17 浏览次数:20602 次
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <body id='pagebody'> <script type="text/javascript" language="javascript"> function addDiv(divID,refLeft,refTop,strMsg){ var l=0; var t=0; var id=''; try{ l=parseInt(refLeft); t=parseInt(refTop); id=divID; }catch(e){ l=300; t=100; id='div'+Math.floor(Math.random()*1000); } var o=document.getElementById(id); if(!o){ var oDiv=document.createElement("DIV"); oDiv.id=id; oDiv.style.position='absolute'; oDiv.style.font='italic normal 12px/20px arial'; oDiv.style.color='blue'; oDiv.style.left=l+'px'; oDiv.style.top=t+'px'; oDiv.style.border='1px solid red'; if(strMsg.length=0) strMsg="empty." oDiv.innerHTML=strMsg; var pb=document.getElementById('pagebody'); pb.appendChild(oDiv); }else{ o.innerHTML='div EXIST already,----'+o.innerHTML; } } </script> <a href="javascript:addDiv('aa',100,300,'EXAMPLE : add new DIV by JS ');">add DIV </a> </body> </html>
------解决方案--------------------
动态添加的标签。。最好是动态赋予它的属性