日期:2014-05-16  浏览次数:20361 次

select 左右多选 demo js
<script type="text/javascript">
// submit
     $(function(){
       $("#id_save").click(function(){
        if(chkform()){
        // alert('submit()');
        $("form").attr("action","<%=request.getContextPath()%>/tmlportal/tml_saveUserDefinedTmlGroupMember.action");
        $("form").submit();
     }
    else{
     return false;
   }
    });
   });
    //check  the input value;
function chkform() {
var selFlag = false;
$("#rightmodel option").each(function(){
if($(this).val() != ""){
// if  this value is not null, attr this selected to selected;
$(this).attr("selected","selected");
selFlag = true;
}
});
//
if(!selFlag) {
alert("必须选择一个终端!");
return false;
}
return selFlag;

}
// remove  left  option to right;
function leftToRight(){
   //leftmodel
var leftmodel = document.getElementById("leftmodel");
//rightmodel
var rightmodel = document.getElementById("rightmodel");
if(leftmodel.length>0){
    // 判读 有没有被选中一个 option。
var leftSelectedIndex = leftmodel.selectedIndex;
if(leftSelectedIndex<0){
option = leftmodel.options(0);
rightmodel.appendChild(option);
}

if(leftSelectedIndex>=0){
  //leftmodel length
    var leftLength = leftmodel.length;
    var i=0;
       for(i;i<leftLength;i++){
         if(leftmodel[i].selected){
           option = leftmodel.options(i);
           rightmodel.appendChild(option);
           repeat();
           // 当移除 选中时,对象长度减少一个。
           leftLength--;
           i--;
         }
        
       }
      
   }//if leftSelectedIndex>=0

// rightmodel.selectedIndex=-1;
this.repeat();

}// 长度 大于0


    }
    // remove all left options  to right sw
function leftToRightAll(){
var leftmodel = document.getElementById("leftmodel");
var rightmodel = document.getElementById("rightmodel");
while(leftmodel.length>0){
rightmodel.appendChild(leftmodel.options(0));
}
this.repeat();
}
// remove right option to left;
function rightToLeft(){

var leftmodel = document.getElementById("leftmodel");
var rightmodel = document.getElementById("rightmodel");
if(rightmodel.length>0){

var rightSelectedIndex = rightmodel.selectedIndex;
if(rightSelectedIndex<0){
rightSelectedIndex=0;
option = rightmodel.options(rightSelectedIndex);
leftmodel.appendChild(option);
}
if(rightSelectedIndex&g