一个页面上有两个控件 一个下拉列表 一个 文本框
一个下拉列表框里两个内容一个是 正常 一个是不正常  当选择正常时 如何让后面的文本变为只读,也就是不能输入东西的文本框 望大虾指点

解决方案 »

  1.   

    在dropDownList的SelectedIndexChanged中,判断后设置文本框TextBox的Readonly属性为true
      

  2.   

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" 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>无标题页</title>
        
        <script language ="javascript" >
        
            window .onload = test;
            
            function test()
            {
                if(document .getElementById ("Select1").options[0].selected)
                {
                    document .getElementById ("t").readOnly = "readOnly" ;
                }
                if(document .getElementById ("Select1").options[1].selected)
                {
                    document .getElementById ("t").readOnly = "" ;
                }
            }
        
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <input type="text" id="t" />
            <select id="Select1" onchange ="test();">
                <option>正常</option>
                <option>不正常</option>
            </select>
            <br />
        </div>
        </form>
    </body>
    </html>