【发布时间】:2014-02-24 08:43:27
【问题描述】:
我试图在我的页面上添加一个文本弹出框,这段代码帮助了我,但我需要添加一个关闭图标(这是我的代码中的一个图像)..
但它不起作用:/
这是我的代码:
function show_hide_box(an, width, height, borderStyle) {
if (navigator.userAgent.indexOf("MSIE") != -1) {
var browserIsIE = true;
} else { browserIsIE = false; }
var href = an.href;
var boxdiv = document.getElementById(href);
if (boxdiv != null) {
if (boxdiv.style.display=='none') {
move_box(an, boxdiv);
boxdiv.style.display='block';
} else
boxdiv.style.display='none';
return false;
}
boxdiv = document.createElement('div');
boxdiv.setAttribute('id', href);
boxdiv.style.display = 'block';
boxdiv.style.position = 'absolute';
boxdiv.style.width = width + 'px';
boxdiv.style.height = height + 'px';
boxdiv.style.border = borderStyle;
boxdiv.style.backgroundColor = '#FFF';
var inClosebox = document.createElement("div");
inClosebox.setAttribute('id', 'Close');
inClosebox.style.position = 'absolute';
if (browserIsIE) {
inClosebox.style.left = '-1px';
inClosebox.style.top = '0px';
} else {
inClosebox.style.left = '-15px';
inClosebox.style.top = '-15px';
}
inClosebox.style.visibility = 'hidden';
var inImage2 = document.createElement("img");
inImage2.onclick = function () { this.document.close(); };
inImage2.setAttribute('src', '../../Images/closebox.png');
inImage2.setAttribute('width', '30');
inImage2.setAttribute('height', '30');
inImage2.setAttribute('border', '0');
inImage2.style.cursor = 'pointer';
inClosebox.appendChild(inImage2);
var contents = document.createElement('iframe');
contents.scrolling = 'yes';
contents.frameBorder = '0';
contents.style.width = width + 'px';
contents.style.height = height + 'px';
contents.src = href;
boxdiv.appendChild(contents);
boxdiv.appendChild(inClosebox);
document.body.appendChild(boxdiv);
move_box(an, boxdiv);
return false;
}
有什么可以帮帮我的吗?
【问题讨论】:
-
如果您使用的是 firefox,请使用 /Download Firebug 并尝试将 closebox 定位到您想要的位置,您可以在您的 css 中使用这些值
-
尝试在一个类中设置样式并简单地给你的元素类名
-
我愿意..并且确实使用萤火虫。但是代码closebox根本没有出现。我想知道我的代码是否有问题?
-
就像 naveen 建议的那样检查图像是否在正确的路径中
-
如果我想从页面中检索特定部分,我可以这样做吗?我的意思是在这部分: var href = an.href; var boxdiv = document.getElementById(href);我可以指定一个标签的 ID 来检索它吗?喜欢:var href = an.href; var boxdiv = document.getElementById(href).getElementById("显示这部分!"); ??
标签: javascript popup