基本思路:
    上移:(1)获取当前选中的元素的索引值
            (2)判断当前元素是否为第一个元素
            (3)如果是,则不执行上移操作,如果不是,则则调用insertBefore方法插入到他的prev(紧邻的上一个)元素之前
 var up = function () {
var selectedIndex = $("#SelectedAddressIds option:selected").index(); //获取当前选中元素的索引
if(selectedIndex >= 1){
// 插入上一个
$("#SelectedAddressIds option:selected").insertBefore($("#SelectedAddressIds option:selected").prev('option'));
}
}
  下移:(1)获取所有option元素的索引值
              (2)获取当前选中元素的索引值
              (3)判断当前选中元素是否为最后一个元素,如果是,则不执行下移,如果不是则调用insertAfter方法插入到他的next(紧邻的下一个)元素的后面。
 var down = function () {
// 获取最后一个option的索引值
var optionNum = $("#SelectedAddressIds option").size() - 1;
// 获取当前选中元素的索引值
var selectedIndex = $("#SelectedAddressIds option:selected").index(); if(selectedIndex < 6){
// 插入下一个
$("#SelectedAddressIds option:selected").insertAfter($("#SelectedAddressIds option:selected").next('option'));
}
}
04-10 23:15
查看更多