标签:
(function() {
var leftSelectObj = document.getElementById(‘leftSelect‘);
var leftBtnUp = document.getElementById(‘left_btn_up‘);
var leftBtnDown = document.getElementById(‘left_btn_down‘);
var rightSelectObj = document.getElementById(‘rightSelect‘);
var rightBtnUp = document.getElementById(‘right_btn_up‘);
var rightBtnDown = document.getElementById(‘right_btn_down‘);
var btnLeft = document.getElementById(‘btn_left‘);
var btnLeftAll = document.getElementById(‘btn_left_all‘);
var btnRight = document.getElementById(‘btn_right‘);
var btnRightAll = document.getElementById(‘btn_right_all‘);
leftBtnDown.onclick = function() {
var index = leftSelectObj.selectedIndex;
if(index !== -1) {
if(index === leftSelectObj.length - 1) {
leftSelectObj.insertBefore(leftSelectObj.children[index], leftSelectObj.children[0]);
} else {
leftSelectObj.insertBefore(leftSelectObj.children[index], leftSelectObj.children[index + 2]);
}
}
};
leftBtnUp.onclick = function() {
var index = leftSelectObj.selectedIndex;
if(index !== -1) {
if(index === 0) {
leftSelectObj.appendChild(leftSelectObj.children[index]);
} else {
leftSelectObj.insertBefore(leftSelectObj.children[index], leftSelectObj.children[index - 1]);
}
}
};
btnRight.onclick = function() {
var index = leftSelectObj.selectedIndex;
if(index !== -1) {
rightSelectObj.appendChild(leftSelectObj.children[index]);
}
};
btnRightAll.onclick = function() {
for(var i = 0; i < leftSelectObj.length; ++i) {
rightSelectObj.appendChild(leftSelectObj.children[i]);
--i;
}
};
})();
标签:
原文地址:http://www.cnblogs.com/wangchen623/p/5701701.html