2个下拉框移动数据,判断重复的问题. 用两个Map存储应该可以更好的解决 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 由于我是在前台页面上的操作,所以我这用的是JS的操作。你说的MAP 是打算走后台呢 还是前台页面里用JS构建对象,还是什么 前台 也应该认ArrayList吧,B的都存进去 每次都for循环 判断ArrayList.Contains(A[i]),速度应该不会慢。 如果慢得无法忍受的话,那就用ajax,把这种要求性能的工作交给服务器吧 同意先把B取出来放到一个结构里A循环到这个结构比较 不要每次都取B的值 为什么要判断呢,直接覆盖不行吗?最好做成hashtable的形式,去覆盖相同的项。ajax后台做 把B里面的下拉的Value组合成一个字符串,A里面选中的作为一个字符串,用indexOf的去查询,这样应该可以把 贴下我这个慢的要命的JS代码/** * oSourceSel 源下拉框 * oTargetSel 目的下拉框 * temp 未选择时的提示语句 * * */function moveSelected(oSourceSel,oTargetSel){ //建立存储value和text的缓存数组 var arrSelValue = new Array(); var arrSelText = new Array(); //此数组存贮选中的options,以value来对应 var arrSelOption = new Array(); var flag=0; //存储源列表框中所有的数据到缓存中,并建立value和选中option的对应关系 var ii=oSourceSel.selectedIndex; if(ii<0) { return; } if(oSourceSel.options.length!=0) { for(var i=0; i<oSourceSel.options.length; i++) { if(oSourceSel.options[i].selected) { //存储 if(oSourceSel.options[i].value==-1) { alert("请选择一条记录。"); return false; } arrSelValue[arrSelValue.length] = oSourceSel.options[i].value; arrSelText[arrSelText.length] = oSourceSel.options[i].text; //建立value和选中option的对应关系 arrSelOption[arrSelOption.length] = oSourceSel.options[i]; } } } else { alert("请选择一条或多条记录。"); return; } for(var i=0; i<arrSelValue.length; i++) { for(var j=0;j<oTargetSel.options.length;j++) { if(oTargetSel.options[j].value==arrSelValue[i]) { alert(arrSelText[i]+"重复。"); return ; } } } //增加缓存的数据到目的列表框中 for(var i=0; i<arrSelValue.length; i++) { //增加 var oOption = document.createElement("option"); oOption.text = arrSelText[i]; oOption.value = arrSelValue[i]; oTargetSel.add(oOption); //删除源列表框中的对应项 flag=1; } if(flag==0) { alert("请选择一条或多条记录。"); return; }} 哈哈!要是我也会采用你的这种方式!不过倒是可以试一下Map ,在网上有用js写的Map,引一下就可以用了!至于速度吗?试验一下就知道了! 不知道咋给分啊这样吧... while(未分配分数>0&&发贴距今时间<10天) { if(回复的) { +2分; if(回复内容较好) { +10分; } if(拿代码来说话的) { +20分; } } } 揭贴;先来先得没有特殊情况的话,送完为止 function move(id,item,selectitem) { if(id==1) //宸︾Щ { if(item.selectedIndex!=-1) { for(var i=item.options.length-1;i>=0;i--) { if(item.options[i].selected) { if(selectitem.options.length==0){ selectitem.add(new Option(item.options[i].text,item.options[i].value)); item.options.remove(i); continue; } var f=false; for(var j=selectitem.options.length-1;j>=0;j--) { // alert(selectitem.options[j].text+" "+item.options[i].text); // if(selectitem.options[j].text!=item.options[i].text) // { // selectitem.add(new Option(item.options[i].text,item.options[i].value)); // item.options.remove(i); // break; // } if(selectitem.options[j].text==item.options[i].text){ f=true; break; } // if(j==0){ // alert("有重复值"); // break; // } } if(!f){ selectitem.add(new Option(item.options[i].text,item.options[i].value)); item.options.remove(i); }else{ alert("有重复值"); } } } } } else if(id==2) //宸︾Щ鍏ㄩ儴 { if(item.length>0){ for(var i=0;i<item.length;i++) { var f=false; if(selectitem.options.length==0){ selectitem.add(new Option(item.options[i].text,item.options[i].value)); item.options.remove(i); continue; } for(var j=selectitem.options.length-1;j>=0;j--) { if(selectitem.options[j].text==item.options[i].text){ f=true; break; } } if(!f){ selectitem.add(new Option(item.options[i].text,item.options[i].value)); item.options.remove(i); }else{ alert("有重复值"); } } for(var i=item.length-1;i>=0;i--) { item.remove(i); } } } else if(id==3) //鍙崇Щ { if(selectitem.selectedIndex!=-1) { for(var i=selectitem.length-1;i>=0;i--) { if(selectitem.options[i].selected) { item.add(new Option(selectitem.options[i].text,selectitem.options[i].value)); selectitem.options.remove(i); } } } } else { if(selectitem.length>0){ for(var i=0;i<selectitem.length;i++) { item.add(new Option(selectitem.options[i].text,selectitem.options[i].value)); } for(var i=selectitem.length-1;i>=0;i--) { selectitem.remove(i); } } } } 上面的传两个select的对象就行啦 包括 左移 左移全部 右移 右移全部的 jsp提交表单错误 hibernate级联保存时候报错!请大家帮帮忙 js文件导入分前后顺序? weblogic +struts+Myeclipse jsp新手关于jstl的问题 运行index.jsp既下面的内容出现错误,请问大哥,大姐是怎么会事阿?????? 引进文件问题 超诡异啊。同样的语句,直接在叶面里就可以连数据库,想写个bean就不行了? 循环跳出,问题。解决马上给分 局域网中网关wingate封了我们QQ端口,有什么方法可以让QQ上线呀 关于 <c:forEach>的一个问题,高手帮帮我吧,实在没招了! 求解决ssh整合出现的异常
同意
先把B取出来放到一个结构里
A循环到这个结构比较 不要每次都取B的值
这样应该可以把
/**
* oSourceSel 源下拉框
* oTargetSel 目的下拉框
* temp 未选择时的提示语句
*
*
*/function moveSelected(oSourceSel,oTargetSel)
{
//建立存储value和text的缓存数组
var arrSelValue = new Array();
var arrSelText = new Array();
//此数组存贮选中的options,以value来对应
var arrSelOption = new Array();
var flag=0;
//存储源列表框中所有的数据到缓存中,并建立value和选中option的对应关系
var ii=oSourceSel.selectedIndex;
if(ii<0)
{
return;
}
if(oSourceSel.options.length!=0)
{
for(var i=0; i<oSourceSel.options.length; i++)
{
if(oSourceSel.options[i].selected)
{
//存储
if(oSourceSel.options[i].value==-1)
{
alert("请选择一条记录。");
return false;
}
arrSelValue[arrSelValue.length] = oSourceSel.options[i].value;
arrSelText[arrSelText.length] = oSourceSel.options[i].text;
//建立value和选中option的对应关系
arrSelOption[arrSelOption.length] = oSourceSel.options[i];
}
}
}
else
{
alert("请选择一条或多条记录。");
return;
}
for(var i=0; i<arrSelValue.length; i++)
{
for(var j=0;j<oTargetSel.options.length;j++)
{
if(oTargetSel.options[j].value==arrSelValue[i])
{
alert(arrSelText[i]+"重复。");
return ;
}
}
}
//增加缓存的数据到目的列表框中
for(var i=0; i<arrSelValue.length; i++)
{
//增加
var oOption = document.createElement("option");
oOption.text = arrSelText[i];
oOption.value = arrSelValue[i];
oTargetSel.add(oOption);
//删除源列表框中的对应项
flag=1;
}
if(flag==0)
{
alert("请选择一条或多条记录。");
return;
}
}
至于速度吗?试验一下就知道了!
这样吧... while(未分配分数>0&&发贴距今时间<10天)
{
if(回复的)
{
+2分;
if(回复内容较好)
{
+10分;
}
if(拿代码来说话的)
{
+20分;
}
}
}
揭贴;先来先得没有特殊情况的话,送完为止
{
if(id==1) //宸︾Щ
{
if(item.selectedIndex!=-1)
{
for(var i=item.options.length-1;i>=0;i--)
{
if(item.options[i].selected)
{
if(selectitem.options.length==0){
selectitem.add(new Option(item.options[i].text,item.options[i].value));
item.options.remove(i);
continue;
}
var f=false;
for(var j=selectitem.options.length-1;j>=0;j--)
{
// alert(selectitem.options[j].text+" "+item.options[i].text);
// if(selectitem.options[j].text!=item.options[i].text)
// {
// selectitem.add(new Option(item.options[i].text,item.options[i].value));
// item.options.remove(i);
// break;
// }
if(selectitem.options[j].text==item.options[i].text){
f=true;
break;
}
// if(j==0){
// alert("有重复值");
// break;
// }
}
if(!f){
selectitem.add(new Option(item.options[i].text,item.options[i].value));
item.options.remove(i);
}else{
alert("有重复值");
}
}
}
}
}
else if(id==2) //宸︾Щ鍏ㄩ儴
{
if(item.length>0){
for(var i=0;i<item.length;i++)
{
var f=false;
if(selectitem.options.length==0){
selectitem.add(new Option(item.options[i].text,item.options[i].value));
item.options.remove(i);
continue;
}
for(var j=selectitem.options.length-1;j>=0;j--)
{
if(selectitem.options[j].text==item.options[i].text){
f=true;
break;
}
}
if(!f){
selectitem.add(new Option(item.options[i].text,item.options[i].value));
item.options.remove(i);
}else{
alert("有重复值");
}
}
for(var i=item.length-1;i>=0;i--)
{
item.remove(i);
}
}
}
else if(id==3) //鍙崇Щ
{
if(selectitem.selectedIndex!=-1)
{
for(var i=selectitem.length-1;i>=0;i--)
{
if(selectitem.options[i].selected)
{
item.add(new Option(selectitem.options[i].text,selectitem.options[i].value));
selectitem.options.remove(i);
}
}
}
}
else
{
if(selectitem.length>0){
for(var i=0;i<selectitem.length;i++)
{
item.add(new Option(selectitem.options[i].text,selectitem.options[i].value));
}
for(var i=selectitem.length-1;i>=0;i--)
{
selectitem.remove(i);
}
}
}
}
包括 左移 左移全部 右移 右移全部的