首页  >  文章  >  web前端  >  基于JQUERY的两个ListBox子项互相调整的实现代码_jquery

基于JQUERY的两个ListBox子项互相调整的实现代码_jquery

WBOY
WBOY原创
2016-05-16 18:06:551356浏览

HTML:

复制代码 代码如下:















未选择颜色


已选择颜色










对应JS方法:
复制代码 代码如下:

function listMove(main, follow, hidetextbox, isBack, index) {
if (index return;
var o = undefined;
var source;
var distinct;
var dddd;
if (!isBack) {
//使用getElementById在IE6中存在BUG
source = $('#' + main);// window.document.getElementById(main);
distinct = $('#' + follow); //window.document.getElementById(follow);
}
else {
source = $('#' + follow); // window.document.getElementById(follow);
distinct = $('#' + main); // window.document.getElementById(main);
}
var hid = $('#' + hidetextbox)[0]; // document.getElementById(hidetextbox);
if (index != undefined) {
var op = "option:eq(" + index + ")";
source.find(op).each(function () {
distinct.append("");
$(this).remove();
});
}
else {
source.find("option:selected").each(function () {
$(this).remove();
distinct.append("");
});
}
var str = "";
//遍历Listbox,取得选中项的值
$('#' + main + ' option').each(function () {
str += $(this).val() + ',';
});
hid.value = str;
}
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn