关于数据选择的问题 http://lucky.myrice.com/javascriptexam/add_del_Select.htm 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <script language=javascript>function selectMove(oSource,oTarget,cWhich) //两个选择框选项之间的移动,oSource为源选择框,oTarget为目标选择框,cWhich为提示文字,取值”左“或”右“。{ if(!oSource.options.length) { alert(cWhich+"侧列表中已没有选项可选,无法移动!"); return; } if(oSource.selectedIndex==-1) { alert("操作前您首先应该从"+cWhich+"侧列表中选择一项!"); return; } var mySld=new Array(); for(i=0;i<oSource.options.length;i++) if(oSource.options[i].selected) mySld[mySld.length++]=i; for(i=0;i<mySld.length;i++) { oTarget.options.length++; oTarget.options[oTarget.options.length-1].text=oSource.options[mySld[i]].text; oTarget.options[oTarget.options.length-1].value=oSource.options[mySld[i]].value; } for(i=0;i<mySld.length;i++) { for(j=mySld[i]-i;j<oSource.options.length-1;j++) { oSource.options[j].text=oSource.options[j+1].text; oSource.options[j].value=oSource.options[j+1].value; } oSource.options.length--; }}function moveAll(oSource,oTarget){ var n=oTarget.options.length; oTarget.options.length=n+oSource.options.length; for(i=n;i<oTarget.options.length;i++) { oTarget.options[i].text=oSource.options[i-n].text; oTarget.options[i].value=oSource.options[i-n].text.value; } oSource.options.length=0;}</script><form name=form1><table class=setrole_tab> <tr> <td> 未加入角色<br> <select size=15 style="width:150px;" name=notadded_role ondblclick="selectMove(document.form1.notadded_role,document.form1.added_role,'左')" multiple> <option>aaaaaaaa</option> <option>bbbbbbbb</option> <option>cccccccc</option> <option>dddddddd</option> </select> </td> <td> <a href="javascript:moveAll(document.form1.notadded_role,document.form1.added_role);">全部右移</a><br> <a href="javascript:selectMove(document.form1.notadded_role,document.form1.added_role,'左')"><img src=images/move_right.gif alt=右移></a><br> <a href="javascript:selectMove(document.form1.added_role,document.form1.notadded_role,'右')"><img src=images/move_left.gif alt=左移></a><br> <a href="javascript:moveAll(document.form1.added_role,document.form1.notadded_role);">全部左移</a> </td> <td> 已加入角色<br> <select size=15 style="width:150px;" name=added_role ondblclick="selectMove(document.form1.added_role,document.form1.notadded_role,'右')" multiple> <option>eeeeeeee</option> <option>ffffffff</option> <option>gggggggg</option> </select> </td> </tr></table></form>提示:按住Ctrl键可进行多选 JS读取dataset的问题 用Javascript获取Yahoo!的YQL上的数据 关于window.onload问题 问个简单问题~! 这段滚屏代码不兼容是哪里的原因? 求javascript控制excel不自动换行的代码? 非常急,如何判断图片的路径 javascript如何判断输入是否是数字,而且是整数? 能否用js判断移动端是否黑屏,或关机等状态 本地项目启动没问题,发布到云服务器上之后提示找不到数据库中的表 请问曾经CSDN介绍过纯用javascript制作的画图组件是什么 关于给文本框赋值的问题
function selectMove(oSource,oTarget,cWhich) //两个选择框选项之间的移动,oSource为源选择框,oTarget为目标选择框,cWhich为提示文字,取值”左“或”右“。
{
if(!oSource.options.length)
{
alert(cWhich+"侧列表中已没有选项可选,无法移动!");
return;
}
if(oSource.selectedIndex==-1)
{
alert("操作前您首先应该从"+cWhich+"侧列表中选择一项!");
return;
}
var mySld=new Array();
for(i=0;i<oSource.options.length;i++)
if(oSource.options[i].selected)
mySld[mySld.length++]=i;
for(i=0;i<mySld.length;i++)
{
oTarget.options.length++;
oTarget.options[oTarget.options.length-1].text=oSource.options[mySld[i]].text;
oTarget.options[oTarget.options.length-1].value=oSource.options[mySld[i]].value;
}
for(i=0;i<mySld.length;i++)
{
for(j=mySld[i]-i;j<oSource.options.length-1;j++)
{
oSource.options[j].text=oSource.options[j+1].text;
oSource.options[j].value=oSource.options[j+1].value;
}
oSource.options.length--;
}
}function moveAll(oSource,oTarget)
{
var n=oTarget.options.length;
oTarget.options.length=n+oSource.options.length;
for(i=n;i<oTarget.options.length;i++)
{
oTarget.options[i].text=oSource.options[i-n].text;
oTarget.options[i].value=oSource.options[i-n].text.value;
}
oSource.options.length=0;
}
</script><form name=form1>
<table class=setrole_tab>
<tr>
<td>
未加入角色<br>
<select size=15 style="width:150px;" name=notadded_role ondblclick="selectMove(document.form1.notadded_role,document.form1.added_role,'左')" multiple>
<option>aaaaaaaa</option>
<option>bbbbbbbb</option>
<option>cccccccc</option>
<option>dddddddd</option>
</select>
</td>
<td>
<a href="javascript:moveAll(document.form1.notadded_role,document.form1.added_role);">全部右移</a><br>
<a href="javascript:selectMove(document.form1.notadded_role,document.form1.added_role,'左')"><img src=images/move_right.gif alt=右移></a><br>
<a href="javascript:selectMove(document.form1.added_role,document.form1.notadded_role,'右')"><img src=images/move_left.gif alt=左移></a><br>
<a href="javascript:moveAll(document.form1.added_role,document.form1.notadded_role);">全部左移</a>
</td>
<td>
已加入角色<br>
<select size=15 style="width:150px;" name=added_role ondblclick="selectMove(document.form1.added_role,document.form1.notadded_role,'右')" multiple>
<option>eeeeeeee</option>
<option>ffffffff</option>
<option>gggggggg</option>
</select>
</td>
</tr>
</table>
</form>
提示:按住Ctrl键可进行多选