<!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 ml; charset=gb2312" /><style>
body {
background-color: #DCDCDC;
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
line-height: 24px;
color: #336699;
}
</style>
<script>function openNewDiv() {  // 新激活图层
  var newDiv = document.createElement("div");
  newDiv.id = "bb";
  newDiv.style.position = "absolute";
  newDiv.style.zIndex = "9999";
  newDiv.style.width = "300px";
  newDiv.style.height = "200px";
  newDiv.style.top = "30px";
  newDiv.style.left = "30px"; // 屏幕居中
  newDiv.style.background = "#EFEFEF";
  newDiv.style.border = "1px solid #860001";
  newDiv.style.padding = "5px";
  
  document.body.appendChild(newDiv);
  document.getElementById("bb").innerHTML = "<html><head><script></script></head></html>";
  
  var newA = document.createElement("a");
  newA.href = "#";
  newA.innerHTML = "关闭激活层";
  newA.onclick = function() {
   document.body.removeChild(bb);
   return false;
  }
  newDiv.appendChild(newA);
}

</script>
</head>
<body>
<a href="#" onclick="openNewDiv();">查询条件</a>
<p>网页内容网页内容网页内容</p></body>
</html>
为什么把 document.getElementById("bb").innerHTML = "<html><head><script></script></head></html>";改成 document.getElementById("bb").innerHTML = "<html><head></head></html>";就可以,我想在这里要写脚本

解决方案 »

  1.   

    <script>不是html标签所以浏览器不认识,如果需要动态执行js,可以使用eval(str);
    str = "function demo() {alert('wariso2008 is mm')}";
      

  2.   

    可不可以这样.document.getElementById("bb").innerHTML = " <html> <head>"+ scripitonMath()+" </head> "
    把scripitonMath()另外定义一个方法呀.
      

  3.   


    去搜索下innerHtml script, 很多不同的技巧只是不同浏览器不同支持http://topic.csdn.net/t/20050623/14/4101762.html