• javascript实现两个asp.net服务器控件ListBox值的互传


    JavaScript新手对有些语法有些疑惑,请高手解惑:

    描述:

      新建asp.net页面

      服务器控件ListBox两个

      Html控件 button两个

    见代码

      

    <body style=" text-align:center;">
        
    <form id="form1" runat="server">
        
    <div>    
             
    <asp:ListBox ID="listLeft" runat="server" Height="199px" Width="160px" >
            
    </asp:ListBox>
            
            
    <input id="turnRight" type="button" onclick ='getLeftListSelected()' value=">>"  style=" top:100px; position: absolute;"/>
            
    <input id="turnLeft"  type="button" onclick ='getRightListSelected()' value="<<" style=" top:140px; " />
            
            
    <asp:ListBox ID="listRight" runat="server" Height="199px" Width="160px">
                
    <asp:ListItem>试验1</asp:ListItem>
                
    <asp:ListItem>试验2</asp:ListItem>
                
    <asp:ListItem>试验3</asp:ListItem>
                
    <asp:ListItem>试验4</asp:ListItem>
                
    <asp:ListItem>试验5</asp:ListItem>
                
    <asp:ListItem>试验6</asp:ListItem>
            
    </asp:ListBox>
        
    </div>
        
    </form>
    </body>

    我的javaScript实现 代码

    代码
        <script  type="text/javascript" >

            
    //      从右边列表往左移    
            function getRightListSelected()   
            {
                var lbRight 
    = document.getElementById("listRight");
                var lbLeft  
    = document.getElementById("listLeft");                               
                
    for( var i = 0;i< lbRight.options.length;++i )
                {
                    
    if( lbRight.options[i].selected ){
                        lbLeft.appendChild( lbRight[i] );
                    } 
                }    
            } 
            
            
    //      从左列表往右移
            function getLeftListSelected()
            {
                var lbRight 
    = document.getElementById("listRight");
                var lbLeft  
    = document.getElementById("listLeft");                                
                
    for( var i = 0;i< lbLeft.options.length;++i )
                {
                    
    if( lbLeft.options[i].selected ){
                        lbRight.appendChild( lbLeft[i] );   
                    } 
                }
            }
     
    </script>

    我想合并后的js代码:

    代码
      <script  type="text/javascript" >     
       
    //      从一个表移到另外一个表  Bug无法识别objfrom
            function Move( objfrom,objto )   
            {
                var lbRight 
    = document.getElementById( objfrom );
                var lbLeft  
    = document.getElementById( objto );                              
                
    for( var i = 0;i< lbRight.options.length;++i )
                {
                    
    if( lbRight.options[i].selected ){
                        lbLeft.appendChild( lbRight[i] );
                    } 
                }    
            } 
        
    </script>

    提示错误:

    lbRight.options对象无法识别

    望高手解惑。。。谢谢!!

  • 相关阅读:
    全景转换工具
    Leetcode 215.数组中的第k个最大元素
    Leetcode 214.最短回文串
    Leetcode 213.大家劫舍II
    Leetcode 212.单词搜索II
    Leetcode 211.添加与搜索单词
    Leetcode 209.长度最小的子数组
    Leetcode 208.实现前缀树
    Leetcode 207.课程表
    Leetcode 206.反转链表
  • 原文地址:https://www.cnblogs.com/yanghucheng/p/1618837.html
Copyright © 2020-2023  润新知