L@_@K
<!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>
  <title> new document </title>
  <meta name="generator" content="editplus" />
  <meta name="author" content="" />
  <meta name="keywords" content="" />
  <meta name="description" content="" />
 </head> <body>
<input type="text" id="a" />
<select id="sel" onchange="return(if (a.value==''){return false;})">
<option value=1>111</option>
<option value=2 selected>222</option>
<option value=3>333</option>
</select>
 </body>
 <script type="text/javascript">
 <!--
function $(sId)
{
return document.getElementById(sId);
}
var oSel = $("sel");
oSel.priviousSelectedIndex = oSel.selectedIndex;
oSel.onchange = function(){
if ($("a").value == "")
{
this.selectedIndex = this.priviousSelectedIndex;
}
};
 //-->
 </script>
</html>

解决方案 »

  1.   

    感谢1楼的答复。
    我还以为还有什么onXXXX的事件激发方法可以解决哩,结果还是要用function来解决。
    我在你的代码加了一句:
    else
         oSel.priviousSelectedIndex = oSel.selectedIndex;
    你的代码变成:.....
        if ($("a").value == "")
        {
            this.selectedIndex = this.priviousSelectedIndex;
        }else
         oSel.priviousSelectedIndex = oSel.selectedIndex;
    .....就非常符合我的需求了。
      

  2.   

    这个片段也许对你有点用处       this.hint = function ( obj )      //设置提示框的颜色
            {   
                if(obj.getAttributeNode("back_style") == null)
                {   var newAtt = document.createAttribute("back_style");
                    newAtt.nodeValue = obj.style.cssText;
                    obj.setAttributeNode( newAtt );
                }
                obj.style.border = "1px dotted #008040";
                obj.style.color  = "#008040";
                obj.style.backgroundColor   = "#F0FFF0";
            }
            //------------------------------------------------
            /* if( obj.style.borderStyle == "dotted" || obj.style.borderStyle == "dotted dotted dotted dotted" )
                myself.hint_back( obj ); */
            //------------------------------------------------
            this.hint_back = function (obj)
            {   if( obj.getAttributeNode("back_style") != null )
                {   obj.style.cssText = obj.getAttribute("back_style");
                }
                else
                    obj.style.cssText = "";
            }