【发布时间】:2011-02-11 15:07:32
【问题描述】:
我在网上找到了一些使用 div 和 CSS opacity 属性在 CSS 中执行“弹出”表单的代码。它适用于 IE 和 Chrome,但不适用于 FireFox。在 Firefox 中,什么也没有发生。我在板上看到了 FireFox CSS 的一些问题,但没有具体到我正在查看的内容。对这个问题的任何帮助都会很棒,因为我对 CSS 很陌生。谢谢!
[Here][1] 是我获取代码以供参考的网站。
CSS
#blanket
{
background-color: #111;
opacity: 0.65;
filter: alpha(opacity=65);
position: absolute;
z-index: 9001;
top: 0px;
left: 0px;
width: 100%;
}
#popUpDiv
{
position: absolute;
background-color: #eeeeee;
width: 300px;
height: 300px;
z-index: 9002;
}
HTML:
<td align="left">
<div id="blanket" style="display: none;">
</div>
<div id="popUpDiv" style="display: none;">
<table>
<tr>
<td>
<a href="#" onclick="popup('popUpDiv')">Close</a>
</td>
</tr>
<tr>
<td style="color: Black;">
Please describe the issue:
</td>
</tr>
<tr>
<td>
<asp:TextBox ID="txtIssue" runat="server" TextMode="MultiLine" Width="275" Height="200"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Button ID="cmdSend" runat="server" Text="Send" />
</td>
</tr>
</table>
</div>
<a href="#" onclick="popup('popUpDiv')">Click here to report an issue.</a>
<br />
<asp:Label ID="lblIssueStatus" runat="server" Text="" Style="color: Red;"></asp:Label>
</td>
JS:
function toggle(div_id) {
var el = document.getElementById(div_id);
if ( el.style.display == 'none' ) { el.style.display = 'block';}
else {el.style.display = 'none';}
}
function blanket_size(popUpDivVar) {
if (typeof window.innerWidth != 'undefined') {
viewportheight = window.innerHeight;
} else {
viewportheight = document.documentElement.clientHeight;
}
if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
blanket_height = viewportheight;
} else {
if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
blanket_height = document.body.parentNode.clientHeight;
} else {
blanket_height = document.body.parentNode.scrollHeight;
}
}
var blanket = document.getElementById('blanket');
blanket.style.height = blanket_height + 'px';
var popUpDiv = document.getElementById(popUpDivVar);
popUpDiv_height=blanket_height/2-150;//150 is half popup's height
popUpDiv.style.top = popUpDiv_height + 'px';
}
function window_pos(popUpDivVar) {
if (typeof window.innerWidth != 'undefined') {
viewportwidth = window.innerHeight;
} else {
viewportwidth = document.documentElement.clientHeight;
}
if ((viewportwidth > document.body.parentNode.scrollWidth) && (viewportwidth > document.body.parentNode.clientWidth)) {
window_width = viewportwidth;
} else {
if (document.body.parentNode.clientWidth > document.body.parentNode.scrollWidth) {
window_width = document.body.parentNode.clientWidth;
} else {
window_width = document.body.parentNode.scrollWidth;
}
}
var popUpDiv = document.getElementById(popUpDivVar);
window_width=window_width/2-150;//150 is half popup's width
popUpDiv.style.left = window_width + 'px';
}
function popup(windowname) {
blanket_size(windowname);
window_pos(windowname);
toggle('blanket');
toggle(windowname);
}
【问题讨论】:
-
您是否检查过是否在 Javascript 错误控制台或 Firebug 中报告了错误?
-
我在 Firefox 3.6.13 中测试并为我工作
-
无法在 Chrome11b 或 FF4b11 中运行:jsfiddle.net/Mutant_Tractor/xdpTM/3
popup not defined -
在 FF 3.0.8 中对我来说很好
-
Firefox 缺少 innerText、outerHTML 属性和 FF 中的兄弟/子节点可以是空文本节点。我没有看到使用这些属性,所以是的,您需要在 firebug 或至少在内置错误控制台 (Ctrl+Shift+J) 中查看错误。
标签: javascript asp.net css