⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 selectlist.js

📁 J2EE学习笔记
💻 JS
字号:
  var displayColumnNumber = 0;

  function enableButton(buttonName,enable) {
	//document.write(buttonName + ":" + enable);
	var img = document.images[buttonName];
	if (img == null) return;
  	var src = img.src;
  	var und = src.lastIndexOf("_disabled.gif");
  	
  	if (und != -1) {
    	if (enable) img.src = src.substring(0,und)+".gif";
  		} else {
    		if (!enable) {
      		var gif = src.lastIndexOf("_clicked.gif");
      		if (gif == -1) gif = src.lastIndexOf(".gif");
      			img.src = src.substring(0,gif)+"_disabled.gif";
    		}
  	}
  	}

	function selectionChanged(selectedElement,unselectedElement,direction,imgUn,img) {
		for(i=0; i<unselectedElement.options.length; i++) {
    			unselectedElement.options[i].selected=false;
 		}

  		form = selectedElement.form;
  		if(direction=="toright"){
  			enableButton(imgUn,
               			(selectedElement.selectedIndex != -1));
               		enableButton(img,
               			(unselectedElement.selectedIndex != -1));
               	}
               	if(direction=="toleft"){
               		enableButton(imgUn,
               			(unselectedElement.selectedIndex != -1));
               		enableButton(img,
               			(selectedElement.selectedIndex != -1));
               	}
	}

	function pushButton(buttonName,push) {
		var img = document.images[buttonName];
		
		if (img == null) return;
		var src = img.src;
		var und = src.lastIndexOf("_disabled.gif");
		if (und != -1) return false;
			und = src.lastIndexOf("_clicked.gif");
		if (und == -1) {
			var gif = src.lastIndexOf(".gif");
			if (push) img.src = src.substring(0,gif)+"_clicked.gif";
		} else {
			if (!push) img.src = src.substring(0,und)+".gif";
		}
	}

	function moveSelected(from,to,direction,imgUn,img) {
		newTo = new Array();
		for(i=0; i<from.options.length; i++) {
			if (from.options[i].selected) {
				newTo[newTo.length] = cloneOption(from.options[i]);
				from.options[i] = null;
				i--;
			}
		}
		for(i=0; i<to.options.length; i++) {
			newTo[newTo.length] = cloneOption(to.options[i]);
			newTo[newTo.length-1].selected = false;
		}
		to.options.length = 0;
		for(i=0; i<newTo.length; i++) {
			to.options[to.options.length] = newTo[i];
		}
		
		if(direction=="toright"){
			selectionChanged(to,from,"toleft",imgUn,img);
		}
		if(direction=="toleft"){
			selectionChanged(to,from,"toright",imgUn,img);
		}
		
		//selectionChanged(to,from,direction);
	}

	function cloneOption(ooption) {
  		var out = new Option(ooption.text,ooption.value);
  		out.name = ooption.name;
  		out.selected = ooption.selected;
  		out.defaultSelected = ooption.defaultSelected;
  		return out;
	}

	function buildData(mlist, data, index, pos,idindex){
		
		
		if (data == null || data == "") return;
		y = mlist.options.length;
		for ( i = 0; i < y; i++){
			mlist.options.remove(0);
		}
		displayColumnNumber = pos;
		for ( i = 0; i < index.length; i++){
			var oOption = document.createElement("OPTION");
			oOption.text=data[index[i]][displayColumnNumber];
			if(idindex == -1){
				oOption.value=index[i];
				oOption.name=index[i];
			}else{
				oOption.value=data[index[i]][idindex];
				oOption.name=index[i];
			}
			//oOption.value=data[index[i]][displayColumnNumber]
			mlist.add(oOption);
		}
	}

	function changeDisplay(availableName,chosenName,dataName,pos){
		list1 = eval("document.all." + availableName);
		list2 = eval("document.all." + chosenName);
		for ( i = 0; i < list1.options.length; i++){
			//alert(eval(dataName)[list1.options(i).value][pos]);
			if(list1.options[i].selected){
				list1.options(i).text = eval(dataName)[list1.options(i).name][pos];
				list1.options[i].selected = true;
			}else{
				//alert("dataName = " + dataName + ":::" + "i = " + i + ":::" + "pos = " + pos);
				list1.options(i).text = eval(dataName)[list1.options(i).name][pos];
			}
		}
		for ( i = 0; i < list2.options.length; i++){
			//alert(list2.options(i).name);
			if(list2.options[i].selected){
				list2.options(i).text = eval(dataName)[list2.options(i).name][pos];
				list2.options[i].selected = true;
			}else{
				list2.options(i).text = eval(dataName)[list2.options(i).name][pos];
			}
		}
	}

	function getChosenItems(chosenName,dataName, pos){
		list2 = eval("document.all." + chosenName);
		
		var ret = new Array();
		for (i = 0; i < list2.options.length; i++){
			ret[i] = eval(dataName)[list2.options(i).name][pos];
		}
		return ret;
	}

	function getAvailableItems(availableName, pos){
		list1 = eval("document.all." + availableName);

		var ret = new Array();
		for (i = 0; i < list1.options.length; i++){
			ret[i] = eval(dataName)[list1.options(i).name][pos];
		}
		return ret;
	}	
	
	
	function selectAll(chosenName){		
		list2 = eval("document.all." + chosenName);
		for(var i=0;i<list2.options.length;i++){
			list2.options[i].selected=true;
		}
	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -