JavaScript来基于另一个下拉列表中自动选择的DropDownList [英] javascript to select dropdownlist automatically based on another dropdown

查看:92
本文介绍了JavaScript来基于另一个下拉列表中自动选择的DropDownList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的网页上2下拉列表,如果我选择相同的所选项目应显示在另一个下拉列表中的项目。任何一个可以给我一个的JavaScript 为了这个,我需要的JavaScript 不是 Jquery的

I am having 2 dropdown lists on my page if i select an item the same selected item should be displayed in another drop down list. Can any one give me a javascript for this i need Javascript not Jquery

推荐答案

试试这个

<asp:DropDownList ID="ddl1" runat="server">
            <asp:ListItem Value="1"></asp:ListItem>
            <asp:ListItem Value="2"></asp:ListItem>
            <asp:ListItem>3</asp:ListItem>
            <asp:ListItem Value="4"></asp:ListItem>
        </asp:DropDownList>
        <asp:DropDownList ID="DropDownList1" runat="server">
            <asp:ListItem>1</asp:ListItem>
            <asp:ListItem>2</asp:ListItem>
            <asp:ListItem>3</asp:ListItem>
            <asp:ListItem>4</asp:ListItem>
            <asp:ListItem></asp:ListItem>
        </asp:DropDownList>



  <script type="text/javascript">
function MyApp(sender){
    var lbMatch = false;
    var loDDL2 = document.getElementById('DropDownList1');
    for(var i=0; i< loDDL2.length-1; i++){
        lbMatch = sender.value==loDDL2.options[i].value;       
        lsSelected = lbMatch ? "<=SELECTED" : "";
        if(lbMatch)
            loDDL2.selectedIndex = sender.selectedIndex;
    }
}
        </script>

在页面加载事件添加此

  ddl1.Attributes.Add("OnChange", "MyApp(this)");

这篇关于JavaScript来基于另一个下拉列表中自动选择的DropDownList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆