问问题
3917 次
2 回答
2
使用.first()
and .last()
,因为您选择了多个元素
//for moving elements up and down
$('.up-button').click(function(){
before = $('#select2 option:selected').first().prev();
$('#select2 option:selected').insertBefore(before);
});
$('.down-button').click(function(){
after = $('#select2 option:selected').last().next();
$('#select2 option:selected').insertAfter(after);
});
于 2013-10-11T06:31:46.683 回答
1
稍微改变了向上/向下逻辑:
$('.up-button').click(function(){
$('#select2 option:selected:first-child').prop("selected", false);
before = $('#select2 option:selected:first').prev();
$('#select2 option:selected').detach().insertBefore(before);
});
$('.down-button').click(function(){
$('#select2 option:selected:last-child').prop("selected", false);
after = $('#select2 option:selected:last').next();
$('#select2 option:selected').detach().insertAfter(after);
});
于 2013-10-11T06:30:26.740 回答