JavaScript-为什么这段代码不起作用
JavaScript - Why is this code not working?
我正在使用JavaScript和CSS,尝试使用iframe
制作一个masic消息框。我希望文档的opacity
为0.4
,并显示消息框。然而,这些都没有发生。我该怎么办?
我的JavaScript
function messageBox(text)
{
document.style.opacity = 0.4;
document.style.filter = 'alpha(opacity=40);';
var box = document.createElement('iframe');
box.setAttribute('id', 'msgBox');
}
我的CSS
#msgBox
{
position:absolute;
top:0;
left:0;
right:0;
bottom:0;
height: 250px;
width: 350px;
background-color: #CCC;
margin: auto;
z-index:9999;
color:white;
box-shadow:1px 1px 1px 1px #444;
}
http://jsfiddle.net/a4m9d/
function messageBox(text){
document.body.style.opacity = 0.4;
document.body.style.filter = 'alpha(opacity="40");';
var box = document.createElement('iframe');
box.id='msgBox';
document.body.appendChild(box);
}
尽管我建议使用div而不是iframe,但为了性能和灵活性,
document
没有style
属性。只有元素具有样式,而document
不是元素。
您希望以<body>
为目标,请尝试使用document.body
。
function messageBox(text) {
document.body.style.opacity = 0.4;
document.body.style.filter = 'alpha(opacity="40");';
var box = document.createElement('iframe');
box.setAttribute('id', 'msgBox');
}
演示:http://jsfiddle.net/a4m9d/3/
相关文章:
- d3js文本传输-示例代码不起作用
- 滚动动画代码不起作用
- 为什么此验证代码不起作用
- 我的jquery代码不起作用.为什么?
- jquery中的PHP代码不起作用
- 谷歌地图代码不起作用
- 为什么这个代码不起作用?我花了很长时间试图弄清楚这一点
- 除非连接插件,否则 jQuery 代码不起作用
- 简单的JavaScript代码不起作用
- Angular资源对我的代码不起作用
- 在加载javascript之前让页面加载的代码不起作用
- 为什么这个jquery代码不起作用
- 直接从代码笔复制的圆环图代码不起作用
- javascript代码不起作用
- javascript验证代码不起作用
- 代码不起作用.我无法确定这个问题
- 为什么这个js代码不起作用
- 重定向到PDF时像素跟踪代码不起作用
- hasClass没有'我的js代码不起作用
- JavaScript-为什么这段代码不起作用