首页 > 代码库 > 移动节点

移动节点

 

 

 function upOrDown(flag){var $List = $(#id‘);var $selectedList =  $List.find(‘option:selected‘);    var len = $selectedList.length;    if(!len){        // 没有选择,不允许上下移动        alert(‘请先选中需要移动的指标‘);        return;    }var index = $selectedList[0].index;        var $optionArr = $List.find(‘option‘);        if(!flag){            if(index == 0){                return ;            }               $selectedList.insertBefore($selectedList.prev(‘option‘));            //changeObj(optionArr[index],optionArr[index - 1]);          }else{            if(index == $optionArr.length - 1){                return;            }            $selectedList.insertAfter($selectedList.next(‘option‘));            //changeObj(optionArr[index],optionArr[index + 1]);        }}/** * 交换两个Select中的Option对象 */function changeObj(sourceObj,targetObj){    // 源对象的值与文本    var sourceVal = sourceObj.value;    var sourceText = sourceObj.text;    var sourceOther = sourceObj[‘other‘];        // 目标对象的值与文本    var targetVal = targetObj.value;    var targetText = targetObj.text;    var targetOther = targetObj[‘other‘];        // 将目标对象赋给源对象    sourceObj.value = http://www.mamicode.com/targetVal;>‘other‘] = targetOther;    sourceObj.selected = false;    // 将源对象赋给目标对象    targetObj.value = http://www.mamicode.com/sourceVal;>‘other‘] = sourceOther;    targetObj.selected = true;}

 

移动节点