很乱,慢慢看看
<script>
function selectAllOptions(obj) {
if (obj=="all"){
for (var i=0; i<document.form1.strUsername.options.length; i++) {
document.form1.strUsername.options[i].selected = true;
}
for (var i=0; i<document.form1.strEdit.options.length; i++) {
document.form1.strEdit.options[i].selected = true;
}
}else{
var iMaxCounter = obj.options.length;
for (var i=0; i<iMaxCounter; i++) {
obj.options[i].selected = true;
}
}
}
function moveSelectedOptions(from) {
var chkselect;
//if (document.form1.admintype[0].checked) {
// from=document.form1.strUsername
for (var i=0; i<from.options.length; i++) {
var o = from.options[i];
if (o.selected) {
chkselect=0;
for (var j=0; j<document.form1.strEdit.options.length; j++) {
if (document.form1.strEdit.options[j].value==o.value){chkselect=1;break;}
}
if (chkselect==0){
document.form1.strEdit.options[document.form1.strEdit.options.length] = new Option( o.text, o.value, true, true);
}
}
}
//}
/*if (document.form1.admintype[1].checked) {
from=document.form1.strAdd
for (var i=0; i<from.options.length; i++) {
var o = from.options[i];
if (o.selected) {
chkselect=0;
for (var j=0; j<document.form1.strEdit.options.length; j++) {
if (document.form1.strEdit.options[j].value==o.value){chkselect=1;break;}
}
if (chkselect==0){
document.form1.strEdit.options[document.form1.strEdit.options.length] = new Option( o.text, o.value, true, true);
}
}
}
}*/
//from.selectedIndex = -1;
}
function delSelectedOptions() {
for (var j=(document.form1.strEdit.options.length-1);j>=0; j--) {
if (document.form1.strEdit.options[j].selected){document.form1.strEdit.options[j]=null;}
}
}
function moveAllOptions(from) {
selectAllOptions(from);
moveSelectedOptions(from);
}
function delAllOptions() {
//if (document.form1.admintype[0].checked) {selectAllOptions(document.form1.strAdd);}
//if (document.form1.admintype[1].checked) {selectAllOptions(document.form1.strEdit);}
selectAllOptions(document.form1.strEdit);
delSelectedOptions();
}
</script>
<script>
function selectAllOptions(obj) {
if (obj=="all"){
for (var i=0; i<document.form1.strUsername.options.length; i++) {
document.form1.strUsername.options[i].selected = true;
}
for (var i=0; i<document.form1.strEdit.options.length; i++) {
document.form1.strEdit.options[i].selected = true;
}
}else{
var iMaxCounter = obj.options.length;
for (var i=0; i<iMaxCounter; i++) {
obj.options[i].selected = true;
}
}
}
function moveSelectedOptions(from) {
var chkselect;
//if (document.form1.admintype[0].checked) {
// from=document.form1.strUsername
for (var i=0; i<from.options.length; i++) {
var o = from.options[i];
if (o.selected) {
chkselect=0;
for (var j=0; j<document.form1.strEdit.options.length; j++) {
if (document.form1.strEdit.options[j].value==o.value){chkselect=1;break;}
}
if (chkselect==0){
document.form1.strEdit.options[document.form1.strEdit.options.length] = new Option( o.text, o.value, true, true);
}
}
}
//}
/*if (document.form1.admintype[1].checked) {
from=document.form1.strAdd
for (var i=0; i<from.options.length; i++) {
var o = from.options[i];
if (o.selected) {
chkselect=0;
for (var j=0; j<document.form1.strEdit.options.length; j++) {
if (document.form1.strEdit.options[j].value==o.value){chkselect=1;break;}
}
if (chkselect==0){
document.form1.strEdit.options[document.form1.strEdit.options.length] = new Option( o.text, o.value, true, true);
}
}
}
}*/
//from.selectedIndex = -1;
}
function delSelectedOptions() {
for (var j=(document.form1.strEdit.options.length-1);j>=0; j--) {
if (document.form1.strEdit.options[j].selected){document.form1.strEdit.options[j]=null;}
}
}
function moveAllOptions(from) {
selectAllOptions(from);
moveSelectedOptions(from);
}
function delAllOptions() {
//if (document.form1.admintype[0].checked) {selectAllOptions(document.form1.strAdd);}
//if (document.form1.admintype[1].checked) {selectAllOptions(document.form1.strEdit);}
selectAllOptions(document.form1.strEdit);
delSelectedOptions();
}
</script>
解决方案 »
- 《深入浅出JavaScript》人民邮电出版社-书中例子无法运行。
- asp.net列印网页时怎么可以不要列印出网址
- IE7中的return false;无效
- div对象和input对象问题:为什么alert(a1.width)能执行;而alert(a2.value)不能执行!
- 如何判断一个URL中是否包含空格或者连续的空格?
- 如果拖动 改变 tables 中 td 的宽度!!
- 将字符串值赋给日期对象的问题,搞不明白,请高手赐教啊!答者有分!
- 小问题,在线等
- 各位高手,是不是在Unload事件中不能提交表单?
- 关于谷歌,360极速,百度浏览器JS兼容性问题
- 关于js参数的页面传递!
- 寻找JavaScript去除一个字符串前后空格的函数或方法?
<FORM name="form1" method="post" action="">
<SELECT style="width:80px" name="sel1" size="8" id="sel1">
<OPTION>aaaa</OPTION>
<OPTION>aaaa</OPTION>
<OPTION>aaaa</OPTION>
<OPTION>aaaa</OPTION>
<OPTION>aaaa</OPTION>
</SELECT>
<SELECT style="width:80px" name="sel2" id="sel2" size="8">
<OPTION>bbbb</OPTION>
<OPTION>bbbb</OPTION>
<OPTION>aaaa</OPTION>
<OPTION>aaaa</OPTION>
</SELECT>
</FORM>
<INPUT type="button" value="leftToRight" onClick="moveAll(document.all.sel1,document.all.sel2)">
<INPUT type="button" value="rightToLeft" onClick="moveAll(document.all.sel2,document.all.sel1)">
</BODY>
<SCRIPT language="javascript">
function moveAll(source, target)
{
var arrSourceValue = new Array();
var arrSourceText = new Array();
var arrTargetValue = new Array();
var arrTargetText = new Array();
var i;
for (i = 0; i < target.options.length; i++)
{
arrTargetValue[i] = target.options[i].value;
arrTargetText[i] = target.options[i].text;
}
for(i = 0; i < source.options.length; i++)
{
arrTargetValue[arrTargetValue.length] = source.options[i].value;
arrTargetText[arrTargetText.length] = source.options[i].text;
}
source.length = 0;
target.length = 0;
for(i = 0; i < arrTargetValue.length; i++)
{
var no = new Option();
no.value = arrTargetValue[i];
no.text = arrTargetText[i];
target[i] = no;
}
}
</SCRIPT>