<div id="showlist" style="position:absolute; border:1pxsolid #ccc;display:none" >&nbsp;</div>
<script>
var str ="<div id=\"child_div\" style=\"background-color:#eee;border-bottom:1px solid #ccc;font-size:9pt;width:366px;\">wc<\/div>"
document.getElementById('showlist').innerHTML=str;
</script>
DIV里要有内容。。
还有。你需要把display:none去掉才可以看到的说。

解决方案 »

  1.   

    另外你的引号引错了。。
    我贴的CODE把display:none去掉直接测试即可。
      

  2.   

    <div id="showlist" style="position: absolute; border: 1pxsolid #ccc; display: block">
        </div>    <script>
        var str = '';
    str+="<div id=\"child_div\" style=\"background-color:#eee;border-bottom:1px solid #ccc;font-size:9pt;width:366px;\">1sd </div>"
    //你的div构造错了
    //display = none的话就看不到div了..document.getElementById('showlist').innerHTML=str;
        </script>
      

  3.   

    to ls
    你测试下:
    <div id="showlist" style="position:absolute; border:1pxsolid #ccc;display:none" >&nbsp;</div>
    <script>
    var str ="<div id=\"child_div\" style=\"background-color:#eee;border-bottom:1px solid #ccc;font-size:9pt;width:366px;\">wc<\/div>"
    var wc = document.getElementById('showlist');
    wc.innerHTML = str;
    wc.style.display = "block";
    </script>
      

  4.   

    我在<div id='showlist'><div>中是有数据的
    刚刚去了display = none,还是不行。
      

  5.   

    昂。。没事。
    不是。。
    //你的div构造错了
    //display = none的话就看不到div了..
    是因为div里没内容。所以找不到它。。
    如果设置了任何非空的内容。。就能获取到它了。。
    这个是IE的BUG。。hb前辈曾经从某帖子说过的样子。。
    而且FF的话。我刚测试了下,需要写在onload里才可以的说。。<div id="showlist" style="position:absolute; border:1pxsolid #ccc;display:none" >&nbsp;</div>
    <script>
    var str ="<div id=\"child_div\" style=\"background-color:#eee;border-bottom:1px solid #ccc;font-size:9pt;width:366px;\">wc<\/div>"
    window.onload = function () {
    var wc = document.getElementById('showlist');
    wc.innerHTML = str;
    wc.style.display = "block";
    }
    </script>
      

  6.   

    //是因为div里没内容。所以找不到它。。
    可以得到啊~~~我糊涂了~~~
      

  7.   

    ls是误会我的意思了,
    我是要获取child_div,
    如document.getElementById('child_div')执行不成功
    var ww = document.getElementById('child_div')
    alert(ww.style.background);执行不成功
      

  8.   

    都是一样的道理。
    你这里写错了。
    str+="<div id=\"child_div" style=\"background-color:#eee;border-bottom:1px solid #ccc;font-size:9pt;width:366px;\" div>"
    你测试下这个。。<div id="showlist" style="position:absolute; border:1pxsolid #ccc;display:none" >&nbsp;</div>
    <script>
    window.onload = function () {
    var str ="<div id=\"child_div\" style=\"background-color:#eee;border-bottom:1px solid #ccc;font-size:9pt;width:366px;\">wc<\/div>",
    wc = document.getElementById('showlist');
    wc.innerHTML = str;
    wc.style.display = "block";
    alert(document.getElementById("child_div").innerHTML);
    }
    </script>
      

  9.   

    document.getElementById("child_div").innerHTML
    可以获取内容
    但是var ww = document.getElementById('child_div')
    alert(ww.style.background);不能成功
      

  10.   

    var str ="<div id=\"child_div\" name=\"zhongguo\" style=\"background-color:#eee;border-bottom:1px solid #ccc;font-size:9pt;width:366px;\">wc<\/div>",
    又如何获取name的值。
      

  11.   

    <div id="showlist" style="position:absolute; border:1pxsolid #ccc;display:none" >&nbsp;</div>
    <script type="text/javascript">
    if ("undefined" != typeof window.HTMLElement && !window.opera) {//兼容FF
    window.HTMLElement.prototype.__defineGetter__("currentStyle", function () {
    return this.ownerDocument.defaultView.getComputedStyle(this,null);
    });
    }
    window.onload = function () {
    var str ="<div id=\"child_div\" style=\"background-color:#eee;border-bottom:1px solid #ccc;font-size:9pt;width:366px;\">wc<\/div>",
    wc = document.getElementById('showlist');
    wc.innerHTML = str;
    wc.style.display = "block";
    var ww = document.getElementById('child_div')
    alert(ww.currentStyle.backgroundColor);
    }
    </script>
      

  12.   

    ls真是强人,背景颜色可以获取了
    我想同时获取,<div id='child_div' name='child_name' value='child_value'>
    希望指点。
      

  13.   

    ls真是强人,背景颜色可以获取了
    我想同时获取,<div id='child_div' name='child_name' value='child_value'>
    中的name,和value的值
    希望指点。
      

  14.   

    <div id="showlist" style="position:absolute; border:1pxsolid #ccc;display:none" >&nbsp;</div>
    <script type="text/javascript">
    if ("undefined" != typeof window.HTMLElement && !window.opera) {//兼容FF
    window.HTMLElement.prototype.__defineGetter__("currentStyle", function () {
    return this.ownerDocument.defaultView.getComputedStyle(this,null);
    });
    /* var c = 
    })*/;
    }String.prototype.RGB_16 = function () {
    return (/^rgb.(\d+), (\d+), (\d+).$/.test(this)) ? (function (a) {
    return "#" + [(a[0] < 16 ? 0 : "") + a[0].toString(16),
    (a[1] < 16 ? 0 : "") + a[1].toString(16),
    (a[2] < 16 ? 0 : "") + a[2].toString(16)].join("");
    })([parseInt(RegExp.$1), parseInt(RegExp.$2), parseInt(RegExp.$3)]) : this;
    };
    window.onload = function () {
    var str ="<div id=\"child_div\" name=\"wcs\" style=\"background-color:#eee;border-bottom:1px solid #ccc;font-size:9pt;width:366px;\">wc<\/div>",
    wc = document.getElementById('showlist');
    wc.innerHTML = str;
    wc.style.display = "block";
    var ww = document.getElementById('child_div')
    alert(ww.currentStyle.backgroundColor.RGB_16());
    alert(ww.getAttribute("name"));
    }
    </script>