zoukankan      html  css  js  c++  java
  • 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对象无法识别

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

  • 相关阅读:
    c#之静态构造函数和单例模式
    ugui之圆角矩形头像实现
    一些网站
    unity3d之实现各种滑动效果
    unity3d之切换场景不销毁物体
    unity3d之技能栏冷却
    unity3d之控制人物转向移动并播放动画
    vs常用快捷键
    构造函数的继承
    编写可维护的javascript 随笔
  • 原文地址:https://www.cnblogs.com/yanghucheng/p/1618837.html
Copyright © 2011-2022 走看看