1 var up = function () { 2 var selectedIndex = $("#SelectedAddressIds option:selected").index(); //获取当前选中元素的索引 3 if(selectedIndex >= 1){ 4 // 插入上一个 5 $("#SelectedAddressIds option:selected").insertBefore($("#SelectedAddressIds option:selected").prev(‘option‘)); 6 } 7 }
1 var down = function () { 2 // 获取最后一个option的索引值 3 var optionNum = $("#SelectedAddressIds option").size() - 1; 4 // 获取当前选中元素的索引值 5 var selectedIndex = $("#SelectedAddressIds option:selected").index(); 6 7 if(selectedIndex < 6){ 8 // 插入下一个 9 $("#SelectedAddressIds option:selected").insertAfter($("#SelectedAddressIds option:selected").next(‘option‘)); 10 } 11 }
原文:http://www.cnblogs.com/enjoymylift/p/5974789.html