我有以下代码,我想将两个DIV标签的不透明度更改为.5。我似乎无法像宽度和高度那样工作。我是否没有正确传递不透明度参数?是否这个newdiv.style.opacity = opacity;
不正确?通过传递函数参数更改Javascript中DIV的不透明度?
<!DOCTYPE html>
<html>
<head>
</head>
<script>
var my_div = null;
var newDiv = null;
function creatediv(id, html, width, height, left, top, opacity)
{
var newdiv = document.createElement('div');
newdiv.setAttribute('id', id);
newdiv.style.width = width + "px";
newdiv.style.height = height + "px";
newdiv.style.position = "absolute";
newdiv.style.left = left + "px";
newdiv.style.top = top + "px";
newdiv.style.background = "#0CC";
newdiv.style.border = "10px solid #000";
newdiv.style.opacity = opacity;
newdiv.innerHTML = 'html n';
document.body.appendChild(newdiv);
my_div = document.getElementById(id);
document.body.insertBefore(newdiv, my_div);
}
</script>
<body onload=" creatediv('xdiv1', 300, 300, 100, 100, .5);creatediv('xdiv2', 30, 30, 100, 100, .5)">
<div id='xdiv1'> </div>
<div id='xdiv2'> </div>
</body>
</html>
我把'opacity'改为'op',没有运气。 – pandoragami 2013-02-24 05:56:51