这量个function好像都不工作,原来在IE下是没有任何问题的。我觉得是document.body.appendChild(elemSpan);没有工作。
这个function的作用是在页面上的一个textbox下粘上一个下拉式菜单。
window.onload = function(){
var elemSpan = document.createElement("span");
elemSpan.id = "spanOutput";
elemSpan.className = "spanTextDropdown";
document.body.appendChild(elemSpan);
} function SetElementPosition(theTextBoxInt){
var selectedPosX = 0;
var selectedPosY = 0;
var theElement = theTextBoxInt;
if (!theElement) return;
var theElemHeight = theElement.offsetHeight;
var theElemWidth = theElement.offsetWidth;
while(theElement != null){
selectedPosX += theElement.offsetLeft;
selectedPosY += theElement.offsetTop;
theElement = theElement.offsetParent;
}
xPosElement = document.getElementById("spanOutput");
xPosElement.style.left = selectedPosX;
if(theTextBoxInt.obj.matchTextBoxWidth)
xPosElement.style.width = theElemWidth;
xPosElement.style.top = selectedPosY + theElemHeight
xPosElement.style.display = "block";
if(theTextBoxInt.obj.useTimeout){
xPosElement.onmouseout = StartTimeout;
xPosElement.onmouseover = EraseTimeout;
}
else{
xPosElement.onmouseout = null;
xPosElement.onmouseover = null;
}
}
这个function的作用是在页面上的一个textbox下粘上一个下拉式菜单。
window.onload = function(){
var elemSpan = document.createElement("span");
elemSpan.id = "spanOutput";
elemSpan.className = "spanTextDropdown";
document.body.appendChild(elemSpan);
} function SetElementPosition(theTextBoxInt){
var selectedPosX = 0;
var selectedPosY = 0;
var theElement = theTextBoxInt;
if (!theElement) return;
var theElemHeight = theElement.offsetHeight;
var theElemWidth = theElement.offsetWidth;
while(theElement != null){
selectedPosX += theElement.offsetLeft;
selectedPosY += theElement.offsetTop;
theElement = theElement.offsetParent;
}
xPosElement = document.getElementById("spanOutput");
xPosElement.style.left = selectedPosX;
if(theTextBoxInt.obj.matchTextBoxWidth)
xPosElement.style.width = theElemWidth;
xPosElement.style.top = selectedPosY + theElemHeight
xPosElement.style.display = "block";
if(theTextBoxInt.obj.useTimeout){
xPosElement.onmouseout = StartTimeout;
xPosElement.onmouseover = EraseTimeout;
}
else{
xPosElement.onmouseout = null;
xPosElement.onmouseover = null;
}
}
{
var elemSpan = document.createElement("span");
elemSpan.id = "spanOutput";
elemSpan.className = "spanTextDropdown";
elemSpan.innerHTML = "xs";
document.body.appendChild(elemSpan);
}我这样测试FF IE6 IE7都没问题
是不是 window.onload被重新覆盖新的值了
这个function是要将在onload时创建的一个object "span" 重新对其中的一些field赋予一定的值,然后将它显示出来。span定义如下:.span.spanTextDropdown{
position: absolute;
top: 0px;
left: 0px;
width: 150;
z-index: 101;
background-color: #C0C0C0;
border: 1px solid #000000;
padding-left: 2px;
overflow: visible;
display: none;
}经过检查SetElementPosition, 我发现在firefox中这几句code都不成功。
xPosElement.style.left = selectedPosX;
if(theTextBoxInt.obj.matchTextBoxWidth)
xPosElement.style.width = theElemWidth;
xPosElement.style.top = selectedPosY + theElemHeight
就是说xPosElement.style没有被重新设值。为什么会这样?估计IE7不工作的原因也在于此。
如何把新值赋进去呢?谢谢。
xPosElement.style.left = selectedPos + "px";
Default.aspx
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Welcome to Raymond's Roogle searching engine</title>
<style type="text/css">
<!--
.style3 {
font-size: 72px;
color: #0000FF;
}
.style4 {color: #FF0000}
.style5 {color: #FFCC00}
.style6 {color: #006633}
.style7 {font-size: 100px}
.style8 {font-size: x-small}
-->
</style>
<LINK href="style.css" type="text/css" rel="stylesheet">style.css:
body, table, div, TR, td
{
font: 8pt verdana;
color: black;
background-color: white;
}
p,th { font-size: 9px; font-weight:bold; color: #666666; line-height: 16px;}
A
{
color:black;
}
a:link { font-size: 9px; font-weight:bold; text-decoration: underline; color: green;}
.span.spanTextDropdown{
position: absolute;
top: 0px;
left: 0px;
width: 150px;
z-index: 101;
background-color: #C0C0C0;
border: 1px solid #000000;
padding-left: 0px;
overflow: visible;
display: none;
}.span.spanMatchText
{
text-decoration: underline;
font-weight: bold;
}.span.spanNormalElement
{
background: #ccffff;
}
.span.spanHighElement
{
background: #ffcccc;
color: red;
cursor: pointer;
}
.span.noMatchData
{
font-weight: bold;
color: #0000FF;
}
element.style.position = "absolute";
element.style.left = "100px";
element.style.top = "100px";
IE6下一点问题都没有。