0
這裏我給我的JavaScript工作正常的IE瀏覽器,但無法正常工作在FireFox。所以請告訴我在javascript中更改哪些內容以便在Firefox中正確運行。需要javascript跨瀏覽器解決方案嗎?
這裏是我的代碼
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Untitled Page</title>
<script type="text/javascript" language="javascript">
var modalWindow = null;
function drawDiv()
{
var txt = document.getElementById('TextBox1');
var dime = new Dimension(txt);
modalWindow = document.createElement('div');
modalWindow.style.position = 'absolute';
modalWindow.setAttribute("align", "center");
modalWindow.setAttribute("vertical-align", "middle");
modalWindow.innerHTML = '<p>hello...</p>';
modalWindow.style.left = dime.x;
modalWindow.style.top = dime.y;
modalWindow.style.width = dime.w;
modalWindow.style.height = dime.h;
modalWindow.style.backgroundColor = '#C0C0C0';
document.body.appendChild(modalWindow);
return false;
}
function hider(whichDiv)
{
document.getElementById(modalWindow).style.display = 'none';
}
function Dimension(element)
{
this.x = -1;
this.y = -1;
this.w = 0;
this.h = 0;
if (element == document)
{
this.x = element.body.scrollLeft;
this.y = element.body.scrollTop;
this.w = element.body.clientWidth;
this.h = element.body.clientHeight;
}
else if (element != null)
{
var e = element;
var left = e.offsetLeft;
while ((e = e.offsetParent) != null)
{
left += e.offsetLeft;
}
var e = element;
var top = e.offsetTop;
while ((e = e.offsetParent) != null)
{
top += e.offsetTop;
}
this.x = left;
this.y = top;
this.w = element.offsetWidth;
this.h = element.offsetHeight;
}
}
</script>
</head>
<body>
<div>
<form id="form1" runat="server">
<asp:TextBox ID="TextBox1" runat="server" Height="180px" Style="left: 307px; position: relative;
top: 264px" TextMode="MultiLine" Width="432px"></asp:TextBox>
<asp:Button ID="Button1" runat="server"
Text="Button" OnClientClick=" return drawDiv()" />
</form>
</div>
</body>
</html>
啊哈!我的眼睛流血了!請介意使用正確的代碼格式嗎?謝謝。 :) – Alex 2010-11-18 06:15:34
轉到[JSBeautifier.org](http://jsbeautifier.org/)並使用網站的格式正確的輸出更新您的代碼。請? – xj9 2010-11-18 06:42:53
你能解釋一下預期的行爲,以及關於實際_problem_儘可能多的信息嗎?例如。 「盒子不是完全正方形」或「當我點擊按鈕時沒有任何反應」。 – ken 2010-11-18 06:56:29