posts - 165, comments - 198, trackbacks - 0, articles - 1
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

javascript select 操作

Posted on 2008-07-04 11:03 G_G 阅读(630) 评论(0)  编辑  收藏 所属分类: javascript
           < input  type ="hidden"  name ="SMSServices"  value ="" />
          
< td >
              
< select  size ="5"   name ="from_SMSServices" >
                  
<% for  (SMSService stmp : SMSServiceUtils.getAllSMSService()) {  %>
                    
< option  value ="<%=stmp.getId()%>" > <% = stmp.getName() %> </ option >
                
<% } %>
              
</ select >
          
</ td >
          
< td >
              
< input  type ="button"   value ='&#62;&#62;'  onclick ="optionSelectedMove(this.form,'from_SMSServices','to_SMSServices');" />< br />
              
< input  type ="button"   value ='&#60;&#60;'  onclick ="optionSelectedMove(this.form,'to_SMSServices','from_SMSServices');" />
          
</ td >
          
< td >
              
< select  size ="5"  name ="to_SMSServices" >
              
</ select >
          
</ td >
      
</ tr >
      
      
< tr >< input  type ="button"  value ="提交"  onClick ="addSMSServicesValues('SMSServices','to_SMSServices');this.form.submit();" /></ tr >



javascript 方法
    function addSMSServicesValues(smsName,selectName){
        
var obj = document.getElementsByName(smsName)[0];
        
var selObj = document.getElementsByName(selectName)[0];
        obj.value 
= '';
        
        
        
for(var i=0;i<selObj.options.length;i++)  {  
              obj.value 
+= selObj.options[i].value+';';
          }
    }
    
function optionSelectedMove(tform,selfromName,seltoName){

        
var selfromObj = document.getElementsByName(selfromName)[0];
        
var seltoObj = document.getElementsByName(seltoName)[0];
        


        
var optmp = null ;
        
for(var i=0;i<selfromObj.options.length;i++)  {  
              
if(selfromObj.options[i].selected==true)  {  
                  optmp 
= selfromObj.options[i];
                  selfromObj.remove(i);
                  
break;
              }  
          }

          
          
//var varItem = new Option(objItemText, objItemValue);     
        seltoObj.options.add(optmp);

    }


只有注册用户登录后才能发表评论。


网站导航: