zoukankan      html  css  js  c++  java
  • JavaScript为DropDownList添加新项

        <script type="text/javascript" language="javascript">
        
    function SearchChange()
        {
            
    var ddl = document.getElementById("DropDownList1")   
            
    var index = ddl.selectedIndex;   
                
            
    var Value = ddl.options[index].value;   
            
    var Text = ddl.options[index].text;
            
            alert(Value);
        }
        </script>

     

    调用:

    <asp:DropDownList ID="DropDownList1" runat="server" onchange="SearchChange();">
        <asp:ListItem Value=
    "0">111</asp:ListItem>
        <asp:ListItem Value=
    "1">222</asp:ListItem>
        <asp:ListItem Value=
    "2">333</asp:ListItem>
    </asp:DropDownList>

     动态为dropdownlist添加项  
    <script type="text/javascript" >
            function ChangeCategory() {
                var dropAppType = document.getElementById("<%=dropAppType.ClientID%>");
                var dropCategory = document.getElementById("<%=dropCategory.ClientID%>");
                var index = dropAppType.selectedIndex;
                if (dropAppType.options[index].text == "Application") {
                    dropCategory.options.length = 0;
                    dropCategory.options[0] = new Option("Comics", "0");
                    dropCategory.options[1] = new Option("Communication", "1");
                    dropCategory.options[2] = new Option("entertainment", "2");
                    dropCategory.options[3] = new Option("Finance", "3");
                    dropCategory.options[4] = new Option("Health", "4");
                    dropCategory.options[5] = new Option("Lifestyle", "5");
                }
                else if (dropAppType.options[index].text == "Games") {
                  dropCategory.options.length =0;
                  dropCategory.options[0]=new Option("arcade&action","0");
                  dropCategory.options[1]=new Option("brain@puzzle","1");
                  dropCategory.options[2]=new Option("cards@casino","2");
                  dropCategory.options[3] = new Option("casual", "3");
              }
              var hidCategory = document.getElementById("hidCategory");
              hidCategory.value = dropCategory.options[index].text;
            }
        </script>

  • 相关阅读:
    UVA1585
    暑期第二场-1
    UVA11582
    UVA10006
    HDU1005
    HDU2035
    POJ:2492-Bug's Life(二分图的判定)
    Codeforces:68A-Irrational problem(暴力大法好)
    Codeforces Round #456 (Div. 2) B. New Year's Eve
    Codeforces Round #456 (Div. 2) A. Tricky Alchemy
  • 原文地址:https://www.cnblogs.com/hubcarl/p/1706290.html
Copyright © 2011-2022 走看看