在列表框里如何实现多选Java,js 多选列表框功能代码

这段代码展示了JavaScript中用于查找DOM对象的函数MM_findObj,以及用于在列表中删除或移动选择项的SelMove函数。SelMove函数接受源列表和目标列表作为参数,并提供了检查选项是否符合特定条件的检查函数checkPostType。此外,还包含了一个全选功能函数SelSelectedAll。这些函数在处理多选列表时非常有用。
摘要由CSDN通过智能技术生成

function MM_findObj(n, d) { //v4.0

var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {

d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}

if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i

for(i=0;!x&&d.layers&&i

if(!x && document.getElementById) x=document.getElementById(n); return x;

}

function checkPostType(des,op){

if(!des || !op) return true;

var flag = true;

var ops = des.options;

var i=0;

for(i=0;i

if(ops.item(i).value==op.value) {

flag=false;

}

if(ops.item(i).value%100==0 && ops.item(i).value==op.value-op.value%100){

flag=false;

}

if(!flag){

alert('选项 ['+ops.item(i).innerText+'] 已经包含了 ['+op.innerText+'].');

return flag;

}

if(op.value%100==0 && op.value==ops.item(i).value-ops.item(i).value%100){

ops.remove(i);

i--;

}

}

return flag;

}

//此函数实现列表中所选择项的删除与移到到别外一个列表中的功能.2001/04/04

//参数表:

//src 源列表

//des 目的列表(如果省略则删除源列表中选中的项)

//exce 如果源列表中某一项的文本与此参数相同则该项不能被移走或删除(可省略)

//d1 指定源列表所在的框架或窗口(如省略则在当前框架或窗口中查找)

//d2 指定目的列表所在的框架或窗口(如省略则在当前框架或窗口中查找)

//

function SelMove(src,des,check,exce,d1,d2,del) {  if (!src) return false;

var oSrc=MM_findObj(src,d1);

if (!oSrc) return false;

if (!des) {

for (i=0;i

if (oSrc.options(i).selected){

if (oSrc.options(i).innerText!=exce) {

oSrc.options.remove(i);

i--;

}

}

}

}

else {

var oDes=MM_findObj(des,d2);

if (!oDes) return false;

for (i=0;i

var oSrcOption =oSrc.options.item(i);

if(oSrcOption.selected){

if(check && check(oDes,oSrcOption)){

if(oSrcOption.innerText!=exce) {

var oOption = document.createElement("OPTION");

oDes.options.add(oOption);

oOption.innerText = oSrcOption.innerText;

oOption.value = oSrcOption.value;

oSrcOption.selected=false;

if(del) {oSrc.options.remove(i);i--;}

}

}

}

}

}

}

function check_City(des,op){

if(checkPostType(des,op)){

if(des.options.length>=3){

alert("不可以超过三个!");

return false;

}

else return true;

}

else {

return false;

}

}

function SelSelectedAll(oSrc){

if(!oSrc) return false;

var i;

for(i=0;i

oSrc.options.item(i).selected=true;

}

}

function check()

{

SelSelectedAll(document.form1.b)

}

1

2

3

4

5

添加

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值