比如说我要在dropdownlist里添加1975-2000的年份,怎么样在javascript中通过循环添加数据?
js该怎么写?

解决方案 »

  1.   

    d = document.getElementById('<%=dropdownlistID.ClientID%>')
    for(i = 1975,i<=2000;i++)
    d.options[d.options.length] = new Option(i,i)
      

  2.   

    服务器 端使用
    Request.Form[dropdownlistID.UniqueID]得到
      

  3.   

    <script language="javascript" type="text/javascript">
            function getdate()
            {
                var d = document.getElementById("year");
                for(i = 1975,i<=2000;i++)
                {
                    d.options[d.options.length] = new option(i,i);
                }
        </script>
    </head>
    <body onload="getdate()">
        <form id="form1" runat="server">
        <div>
            <asp:DropDownList ID="year" runat="Server"></asp:DropDownList>年
            <asp:DropDownList ID="month" runat="Server"></asp:DropDownList>月
            <asp:DropDownList ID="day" runat="server"></asp:DropDownList>日
        </div>
        </form>
    </body>这样错的原因是什么?
      

  4.   

    <script type="text/javascript">
    d = document.getElementById('<%=dropdownlistID.ClientID%>')
    for(i = 1975,i<=2000;i++)
        d.options.add(new Option(i,i);
    </script>
      

  5.   

    Form1.drpproj.add(new Option(text,value));
      

  6.   

    sonce8() 
    ------
    正解!
      

  7.   

    <body onload="getdate()">
        <form id="form1" runat="server">
        <div>
            <asp:DropDownList ID="year" runat="Server"></asp:DropDownList>年
            <asp:DropDownList ID="month" runat="Server"></asp:DropDownList>月
            <asp:DropDownList ID="day" runat="server"></asp:DropDownList>日
        </div><script language="javascript" type="text/javascript">
            function getdate()
            {
                var d = document.getElementById("year");
                for(i = 1975;i<=2000;i++)
                {
                     d.Options.add(new Option(i,i));
                }
    }
        </script>
        </form>
    </body>
      

  8.   

    for(i = 1975,i<=2000;i++)//,应该为;
      

  9.   

    LZ的错误还有js代码应该放到下拉框后面。
      

  10.   

    DropDownList.options.add(new Option("value",index));
      

  11.   

    Form1.drpproj.options.length=0;来清空