<div id="showlist" style="position:absolute; border:1pxsolid #ccc;display:none" > </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去掉才可以看到的说。
<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去掉才可以看到的说。
我贴的CODE把display:none去掉直接测试即可。
</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>
你测试下:
<div id="showlist" style="position:absolute; border:1pxsolid #ccc;display:none" > </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>
刚刚去了display = none,还是不行。
不是。。
//你的div构造错了
//display = none的话就看不到div了..
是因为div里没内容。所以找不到它。。
如果设置了任何非空的内容。。就能获取到它了。。
这个是IE的BUG。。hb前辈曾经从某帖子说过的样子。。
而且FF的话。我刚测试了下,需要写在onload里才可以的说。。<div id="showlist" style="position:absolute; border:1pxsolid #ccc;display:none" > </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>
可以得到啊~~~我糊涂了~~~
我是要获取child_div,
如document.getElementById('child_div')执行不成功
var ww = document.getElementById('child_div')
alert(ww.style.background);执行不成功
你这里写错了。
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" > </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>
可以获取内容
但是var ww = document.getElementById('child_div')
alert(ww.style.background);不能成功
又如何获取name的值。
<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>
我想同时获取,<div id='child_div' name='child_name' value='child_value'>
希望指点。
我想同时获取,<div id='child_div' name='child_name' value='child_value'>
中的name,和value的值
希望指点。
<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>