<script language=javascript>
    function showBackgroundColor(obj){
           var strColor=(obj.value=="1")?"white":"gray"
   document.getElementById("showText").style.backgroundColor= strColor
    }
</script>
<select name="aaa" onchange="showBackgroundColor(this)">
<option value="1">白色</option>
<option value="2">灰色</option>
</select>
<input name="showText">

解决方案 »

  1.   

    <body>
    <select id= "province" onchange="DisplayCity(this.options[this.selectedIndex].text);" align="center" style="width:100px">
    <option value="0"></option>
    <option value="1">between</option>
    <option value="2">gray</option>
    </select>
    </body>
    <script>
    function DisplayCity(text)
    {
        var select=document.getElementById("province");
        if(text == "between")
        {
            select.style.backgroundColor = "#FFFFFF";
        }
        else if(text == "gray")
        {
            select.style.backgroundColor = "gray";
        }
    }
    </script>
      

  2.   


    <script   language=javascript> 
            function   showBackgroundColor(obj){ 
          if(obj.value=="1")
          document.getElementById("showText").style.backgroundColor="white";
      else
          document.getElementById("showText").style.backgroundColor="gray";
            } 
    </script> 
    <select   name="aaa"   onchange="showBackgroundColor(this)"> 
    <option   value="1"> between</option> 
    <option   value="2"> > </option>
    <option   value="3"> = </option> 
    <option   value="4"> < </option> 
    </select> 
    <input   name="showText"> 
      

  3.   

    先谢谢上面几位兄弟!我的开发语言是asp.net(VB)
    设计控件是: "web窗体"的DropDownList控件,而不是"HTML"的DropDown控件"web窗体"DropDownList控件没有onChange事件;只有OnSelectedIndexChanged事件;
    "HTML"的DropDown控件有onChange事件;所以再说一次:
    System.Web.UI.WebControls.DropDownList控件的下拉值改时,
    能不能实现改变System.Web.UI.WebControls.TextBox控件的背景色?
      

  4.   

    完全可以,
    服务器端OnSelectedIndexChanged事件和HTML onChange事件
    是一个道理。而且也在服务器端也可以更改背景属性
      

  5.   

    C# 这样 写客户端事件
    txtGOUZHIRQ.Attributes.Add("onfocus", "setday(this);");
    VB.net没用过
      

  6.   

    问题稿惦了,谢谢各位的热心帮助!
    实现代码如下:
    <script language="javascript"> 
    function showBackgroundColor(obj)

    if(obj.value==1)
    document.getElementById("txtWeight2").style.backgroundColor="white";
    else
    document.getElementById("txtWeight2").style.backgroundColor="gray";

    </script>'启动时加如下代码
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    If Not Page.IsPostBack Then
    DropDownList1.Attributes.Add("onclick", "javascript:showBackgroundColor(this);")
    End If
    End Sub