窗体上有两个dropdownlist控件,如何能用javascript实现这两个dropdownlist控件的选择项的一对多关系。
比如说控件一选择'会计师'这一项,另一个控件的内容选项就变成与会计师有关的职称级别。
能否给出代码实例

解决方案 »

  1.   

    干吗用js呢?.net的处理事件够用了。
    在第一个dropdownlist的selectedIndexChanged事件处理函数中往第二个dropdownlist中添加对应的ListItem就可以了
      

  2.   

    function SelChina()
    {
    switch (document.shengshi.selValue.value)
    {
    case '中国' :
    var values = new Array("深圳","广州","上海");
    var lables = new Array("深圳","广州","上海");
    break;
    case '日本' :
    var values = new Array("123","234","345");
    var lables = new Array("123","234","345");
    break
    }
    document.shengshi.selChina.options.length =0;
    for (var i =0; i<lables.length ; i++)
    {
    document.shengshi.selChina.add(document.createElement("OPTION"));
    document.shengshi.selChina.options[i].value = values[i];
    document.shengshi.selChina.options[i].text = lables[i];
    }
    document.shengshi.selValue.selectedIndex =0;
    }
    </script>
      

  3.   

    搜索:在WEB项目中多维下拉菜单的实现技巧和方法 ^-^
      

  4.   

    用xmlhttp对象进行操作。
    从后台取得数据,然后前台写入option项。
      

  5.   

    <%@ Page Language="C#" AutoEventWireup="false" debug="true" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > 
    <html>
      <head>
        <title>js联动</title>
        <meta name=vs_defaultClientScript content="JavaScript">
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    var hjsRole = new Array();
    for(var i=0;i < 5;i ++)
    {
    hjsRole[hjsRole.length] = "会计师职位" + i.toString();
    }

    function DDLChange()
    {
    if(Form1.DropDownList1.selectedIndex == 1)
    {
    for(var i=0;i<Form1.DropDownList2.options.length;i++)
    {
    Form1.DropDownList2.options[i] = null;
    }
    // 绑定会计师的职位
    for(var i=0;i<hjsRole.length;i++)
    {
    Form1.DropDownList2.options[i] = new Option(hjsRole[i],i.toString());
    }
    }
    else
    {
    // 清空 DropDownList2
    }
    }
    //-->
    </SCRIPT>    <script runat="server">
    private void Page_Load(object sender, System.EventArgs e)
    {
    DropDownList1.Attributes["onchange"] = "DDLChange();";
    if( !IsPostBack )
    {

    }
    } override protected void OnInit(EventArgs e)
    {
    InitializeComponent();
    base.OnInit(e);
    }

    private void InitializeComponent()
    {    
    this.Load += new System.EventHandler(this.Page_Load);
    }
    </script>  </head>
      <body>
        <form id="Form1" method="post" runat="server">
    <asp:DropDownList id="DropDownList1" runat="server">
    <asp:ListItem Value="0" Selected="True">无</asp:ListItem>
    <asp:ListItem Value="1">会计师</asp:ListItem>
    </asp:DropDownList>
    <asp:DropDownList id="DropDownList2" runat="server">
    <asp:ListItem Value="0" Selected="True">无</asp:ListItem>
    </asp:DropDownList>
        </form>
      </body>
    </html>
      

  6.   

    将你的下拉控件的属性autopostback属性设为ture,然后编写SelectedIndexChanged事件