上一篇:右键弹出自定义菜单,很有意思呀! >>
(排序,连选,跳选多项Option)下拉列表框1<=>下拉列表框(改进版)
本程式支持排序,Shift和Ctrl功能!(即:连选和跳选多项Option)
可以任意的相互操作(下拉列表框1<=>下拉列表框2)!
如果多维数组复杂,可以自己写一个排序函数!
Javascript中Sort()所传的参数为数组的俩个RECORD(我的定义),默认按
字符排序。
排序所传的参数也为一个数组,例数组A 为下所示:
a[0][0]=1;
a[0][1]=2;
a[0][2]=3;
a[0][3]=4;
a[1][0]=1;
a[1][1]=2;
a[1][2]=3;
a[1][3]=4;
a[2][0]=1;
a[2][1]=2;
a[2][2]=3;
a[2][3]=4;
每次所传的参数为下:
a[0]={1,2,3,4}
a[1]={1,2,3,4}
。。。。。。。
那么自己根据要求就可以对传来的参数数组(实际为数组中的RECORD)
中的某一个FIELD进行排序!
select.htm
<html>
<head>
<META content="text/html; charset=gb2312" http-equiv=Content-Type>
<link rel="stylesheet" href="common.css">
</head>
<body bgColor=skyblue>
<form action="select.htm" method="post" name="myform">
<br><br><br>
<div align="center"><center><left>
<table style="FONT-SIZE: smaller">
<tr><td>
<table>
<tr><td>
<select name="left_select" style="HEIGHT: 200px; WIDTH: 100px" multiple>
<OPTION VALUE="A">A</OPTION><OPTION VALUE="B">B</OPTION>
<OPTION VALUE="C">C</OPTION><OPTION VALUE="D">D</OPTION>
<OPTION VALUE="E">E</OPTION><OPTION VALUE="F">F</OPTION>
<OPTION VALUE="G">G</OPTION><OPTION VALUE="H">H</OPTION>
<OPTION VALUE="I">I</OPTION><OPTION VALUE="J">J</OPTION>
<OPTION VALUE="K">K</OPTION><OPTION VALUE="L">L</OPTION>
<OPTION VALUE="M">M</OPTION><OPTION VALUE="N">N</OPTION>
<OPTION VALUE="O">O</OPTION><OPTION VALUE="P">P</OPTION>
</select>
</td></tr>
</table>
</td><td>
<table border="0">
<br>
<tr><td>
<INPUT language="javascript" name="btn_select_addany" onclick="fun_select_addany(document.myform)" style="COLOR: blue; FONT-FAMILY: Webdings; FONT-SIZE: 12pt; FONT-WEIGHT: normal; HEIGHT: 28px; WIDTH: 27px" title="Add any" type=button value="8"></td></tr><tr><td>
<INPUT language="javascript" name="btn_select_addall" onclick="fun_select_addall(document.myform)" style="COLOR: blue; FONT-FAMILY: Webdings; FONT-SIZE: 12pt; FONT-WEIGHT: normal; HEIGHT: 28px; WIDTH: 27px" title="Add all" type=button value=: DESIGNTIMESP="17713"></td></tr><tr><td>
<br><br></td></tr><tr><td>
<INPUT language="javascript" name="btn_select_dltany" onclick="fun_select_dltany(document.myform)" style="COLOR: blue; FONT-FAMILY: Webdings; FONT-SIZE: 12pt; FONT-WEIGHT: normal; HEIGHT: 28px; WIDTH: 27px" title ="delete any" type=button value="7"></td></tr><tr><td>
<INPUT language="javascript" name="btn_select_dltall" onclick="fun_select_dltall(document.myform)" style="COLOR: blue; FONT-FAMILY: Webdings; FONT-SIZE: 12pt; FONT-WEIGHT: normal; HEIGHT: 28px; WIDTH: 27px" title ="delete all" type=button value="9"></td></tr>
<tr><td></td></tr>
<tr><td>
</td></tr>
</table></TD><td>
<table style="FONT-SIZE: smaller">
<tr><td>
<select name="right_select" style="HEIGHT: 200px; WIDTH: 100px" multiple>
</select>
</td></tr>
</table>
</td></TR></TBODY></TABLE></div></CENTER>
</form>
</body>
</html>
<script language="javascript">
function fun_select_addany(theform){
var i;
for (i=0;i<theform.left_select.length;i++){
if (theform.left_select.options[i].selected == true){
theform.right_select.options[theform.right_select.length]=new Option(theform.left_select.options[i].text);
theform.left_select.options.remove(i);
i--;
}
}
sort_select(document.myform);
}
function fun_select_addall(theform){
var i;
for (i=0;i<theform.left_select.length;i++){
theform.right_select.options[theform.right_select.length]=new Option(theform.left_select.options[i].text);
}
theform.left_select.length=0;
sort_select(document.myform);
}
function fun_select_dltany(theform){
var i;
for (i=0;i<theform.right_select.length;i++){
if (theform.right_select.options[i].selected == true){
theform.left_select.options[theform.left_select.length]=new Option(theform.right_select.options[i].text);
theform.right_select.options[i] =new Option("");
theform.right_select.options.remove(i);
i--;
}
}
sort_select(document.myform);
}
function fun_select_dltall(theform){
var i;
for (i=0;i<theform.right_select.length;i++){
theform.left_select.options[theform.left_select.length]=new Option(theform.right_select.options[i].text);
}
theform.right_select.length=0;
sort_select(document.myform);
}
function sort_select(theform){
var i;
var left_array= new Array();
var right_array = new Array();
for (i=0;i<theform.left_select.length;i++){
left_array[i] = new Array(theform.left_select.options[i].text);
}
for (i=0;i<theform.right_select.length;i++){
right_array[i] = new Array(theform.right_select.options[i].text);
}
left_array.sort();
right_array.sort();
theform.left_select.length=0;
theform.right_select.length=0;
for (i=0;i<left_array.length;i++){
theform.left_select.options[theform.left_select.length]=new Option(left_array[i]);
}
for (i=0;i<right_array.length;i++){
theform.right_select.options[theform.right_select.length]=new Option(right_array[i]);
}
left_array= new Array();
right_array = new Array();
}
</script>
下一篇:没什么,就是document的一个方法而已,语法见内 >>
相关文章:
- · 客户端JS表格排序---摘自微软.
- · 函数整理(变量和转换函数)
- · 函数整理(条件函数)
- · 函数整理(输入函数)
- · 函数整理(数学函数)
- · 函数整理(字符串函数)
- · 函数整理(日期和时间函数)
- · 动态伸缩ie窗口(酷)(天乐原创)
- · 利 用 ASP 在 客 户 端 注 册 DLL 文 件!
- · 我有2个类似的js,不知道有用否 1
- · 我搜集过一段类似的js,不知道有用否
- · form文本域的通用校验函数
- · 函数控制最小化窗口
- · 用DHTML来模拟实现下拉菜单
- · javascript动态增加、删除、填充表格内容。
- · 最完美的JS万年历(一)
- · 最完美的JS万年历(二)
- · 最完美的JS万年历(三)
- · 用JS定制IE工具栏按钮
- · 看看我写的.和这里样式差不多.不过一样好用哟.滑动时还有音乐.用的qq的音乐
- · 妙用VBScript自制IE工具栏按钮(转)
- · js有几个缺陷。combox1.doSelectIdx(-1)我看不用调用了。
- · 层不能跨框架(包括TEXTAREA)显示的解决办法
- · 罗亭的可输入下拉框的解密简化版.
- · IE里的探索之浏览器概览
- · IE里的探索之向标准上下文相关菜单里添加条目
- · IE里的探索之添加浏览器栏
- · IE里的探索之添加工具条按钮(2)
- · IE里的探索之添加工具条按钮(1)
- · IE里的探索之创建具有良好行为的自定义元素
- · IE里的探索之定制浏览器好助手(上1)
- · IE里的探索之定制浏览器好助手(上2)
- · IE里的探索之定制浏览器好助手(中1)
- · IE里的探索之定制浏览器好助手(下)
- · IE里的探索(想定制自己的IE的可以看一看)
- · 这个object还有其他几种用法.现在贴了给大家.
- · 自动关闭窗口,方法总结
- · 这个脚本可以使你方便得获得各网站的连接速度
