<span>1111</span><input type="text" onfocus="alert(this.previousSibling.innerHTML)" /><span>1111</span>
这样就没事了

解决方案 »

  1.   

    那如果我要获得下一个span节点怎么做呢
      

  2.   

    <body id="www.never-online.net">
    <span>1111</span>
            <input type="text" onfocus="alert(this.previousSibling.innerHTML)" />
    <span>1111</span>
    <script type="text/javascript">
    //<![CDATA[
    var notspace = /\S/;function cleanWhitespace(node) {
        for (var x=0; x<node.childNodes.length; x++) {
          var child = node.childNodes[x];
          if ((child.nodeType == 3) && (!notspace.test(child.nodeValue))) {
            node.removeChild(node.childNodes[x]); x--;
          }; if(child.nodeType == 1) { cleanWhitespace(child); }
        }
    }
    cleanWhitespace(document.body)
    //]]>
    </script>
      </body>
      

  3.   

    再请问一下我通过这样来改变input的样式为什么不生效啊
    <input type="text" onfocus="ClearMessage(this);SetDefaultStyle(this,'333333','f0f8ff')" onblur="ValidateData(9,this,'',1,'ff0000','');SetDefaultStyle(this,'cccccc','eeeeee')" /><div style="display:inline"></div>function SetDefaultStyle(obj,borderColor,bgColor)

      obj.cssText= "\"display:inline;width:175px;BORDER-RIGHT: #"+borderColor+" 1px solid; BORDER-TOP: #"+borderColor+" 1px solid; FONT-SIZE: 12px; BORDER-LEFT: #"+borderColor+" 1px solid; BORDER-BOTTOM: #"+borderColor+" 1px solid; FONT-FAMILY: verdana; BACKGROUND-COLOR: #" + bgColor+"\"";
      alert(obj.cssText);
    }
      

  4.   

    我监视到上面的函数是执行了的
    执行后的csstext也是正确的可是input的外观就是没发生改变
      

  5.   

    先定义不同的样式,修改ClassName
    或者一个一个设置
    .style.width=""
    ... ...
      

  6.   

    <input type="text" onfocus="SetDefaultStyle(this,'333333','f0f8ff')" onblur="SetDefaultStyle(this,'cccccc','eeeeee')" />
    <script type="text/javascript">
    //<![CDATA[
        
    function SetDefaultStyle(obj,borderColor,bgColor)

      obj.style.cssText= "background-color:" +borderColor;
    }
    //]]>
    </script>
      

  7.   

    obj.cssText
    ----------------
    obj.style.cssText