这量个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;
        }
      }

解决方案 »

  1.   

    对不起,写漏了一点,原来的code在IE6下工作没问题,firefox下不工作,现在发现在IE7下也不工作。
      

  2.   

    好象写错了。window.onload = function()
    {
    var elemSpan = document.createElement("span");
    elemSpan.id = "spanOutput";
    elemSpan.className = "spanTextDropdown";
    elemSpan.innerHTML = "xs";
    document.body.appendChild(elemSpan); 
    }我这样测试FF IE6 IE7都没问题 
    是不是 window.onload被重新覆盖新的值了
      

  3.   

    琢磨了半天,发现问题可能在function SetElementPosition(theTextBoxInt)
    这个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不工作的原因也在于此。
    如何把新值赋进去呢?谢谢。
      

  4.   

    折腾了一把,发现得用这样才能把值赋进去:xPosElement.style.left = "100px"; 而不是code中的xPosElement.style.left = selectedPosX; 然后就想先实验一下,直接将值赋给xPosElement.style.left/width/top, 然后用firefox打开,还是不工作(位置不对,style没有被正确地动态更新)谁能告诉我这是什么原因?谢谢。
      

  5.   

    没加传说中的"px"
    xPosElement.style.left = selectedPos + "px";
      

  6.   

    加了"px"也没有用。我觉得整个css都不适用于IE7和FF,以下是我的css和html头。兰色部分会不会有问题?
    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; 
    }
      

  7.   

    蓝色部分不加可能会带出更多的问题我这边只要是这样就没有问题
    element.style.position = "absolute";
    element.style.left = "100px";
    element.style.top = "100px";
      

  8.   

    很不幸,你的code我早就试过,不解决问题。下拉式菜单的内容一直都能正确显示,可是会被显示在错误的位置。而且颜色什么的都没有,证明css没有工作。
    IE6下一点问题都没有。