select.js

来自「用jsp,servlet实现人力资源管理系统」· JavaScript 代码 · 共 47 行

JS
47
字号
function addSelectValue(sourceField, targetField) 
{	
	if (sourceField.options.length > 0) 
	{
		for(var i = 0; i < sourceField.options.length; i++) 
		{
			if(sourceField.options(i).selected) 
			{
			     put = 0;
                 if (targetField.options.length > 0)
                 {
	             	for (j = 0; j < targetField.options.length; j++)
	                {                                
	                	if (targetField.options(j).value == sourceField(i).value)
                        {
                       		put = 1;
                       		break;
                      	}
	                }
                 }
                 
                 if (put == 0)
				 	targetField.options[targetField.options.length] = new Option(sourceField.options(i).text, sourceField.options(i).value)
			}
		}
	}
}

function delSelectValue(sourceField) 
{
	if (sourceField.options.length > 0) 
	{		
		for(var i = sourceField.options.length - 1; i > -1; i--) 
		{
			if(sourceField.options(i).selected) 
			{				
		    	sourceField.options[i] = null
			}
		}
	}	
}

function selectAll(sourceField) 
{
	for(var i = 0; i < sourceField.options.length; i++) 
			sourceField.options(i).selected = true;	
}

⌨️ 快捷键说明

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