?? funlib.js
字號:
// sObjListID1 - 源選擇框一
// sObjListID2 - 源選擇框二
// tObjListID - 目標列表框
// limit - 允許向目標列表框添加的項數(shù)
// combtype - 文本組合類型:1-組合兩個源選框文本,2-組合兩個源選框的值
// joinchar - 源選擇框一選項值與源選擇框二選項值的連接字符
function AddItemToList(sObjListID1, sObjListID2, tObjListID, limit, combtype, joinchar)
{
var sObjList1, sObjList2, tObjList, selectedItem;
sObjList1 = document.getElementById(sObjListID1);
sObjList2 = document.getElementById(sObjListID2);
tObjList = document.getElementById(tObjListID);
if( sObjList1 != null && sObjList2 != null && tObjList != null )
{
if( sObjList1.selectedIndex >= 0 && sObjList2.selectedIndex >= 0)
{
if( tObjList.length < limit || limit == 0 )
{
selectedItem = sObjList2.options[sObjList2.selectedIndex];
for( i=0; i<tObjList.length; i++ )
{
if( tObjList.options[i].value == selectedItem.value )
{
alert("已經(jīng)選擇有該項!");
return;
}
else if( selectedItem.value.indexOf(tObjList.options[i].value)==0 )
{
alert("已經(jīng)選擇了該類不限!");
return;
}
else if( tObjList.options[i].value.indexOf(selectedItem.value)==0 )
{
alert("與已經(jīng)選擇的項有沖突!");
return;
}
}
switch( combtype )
{
case 1:// 組合兩個源選框文本
if(sObjList1.options[sObjList1.selectedIndex].value ==
sObjList2.options[sObjList2.selectedIndex].value)
tObjList.options[tObjList.length] = new Option(
sObjList2.options[sObjList2.selectedIndex].text,
selectedItem.value);
else
tObjList.options[tObjList.length] = new Option(
sObjList1.options[sObjList1.selectedIndex].text + joinchar + selectedItem.text,
selectedItem.value);
tObjList.options[tObjList.length-1].selected = true;
break;
case 2:// 使用源選框二的值
tObjList.options[tObjList.length] = new Option(
selectedItem.value.replace(joinchar, ""), selectedItem.value);
tObjList.options[tObjList.length-1].selected = true;
break;
}
}
else
{
alert("最多只能添加" + limit + "項!");
}
}
}
}
// sObjListID1 - 源選擇框一
// sObjListID2 - 源選擇框二
// tObjListID - 目標列表框
// joinchar - 源選擇框一選項值與源選擇框二選項值的連接字符
// combtype - 值組合類型
// enableoverlap - 源選擇框一與源選擇框二的選項值允許重疊
// limit - 允許向目標列表框添加的項數(shù)
function AddCombinedItemToList(sObjListID1, sObjListID2, tObjListID, joinchar, combtype, enableoverlap, limit)
{
var sObjList1, sObjList2, tObjList;
var aText, aValue;
sObjList1 = document.getElementById(sObjListID1);
sObjList2 = document.getElementById(sObjListID2);
tObjList = document.getElementById(tObjListID);
if( sObjList1 != null && sObjList2 != null && tObjList != null )
{
if( sObjList1.selectedIndex >= 0 && sObjList2.selectedIndex >= 0)
{
switch( combtype )
{
// 組合類型一:文本與值分別連接
case 1:
// 不允許重疊,但源選擇框一選中項與源選擇框二選中項的文本相同
if( !enableoverlap && sObjList1.options[sObjList1.selectedIndex].text == sObjList2.options[sObjList2.selectedIndex].text)
{
aText = sObjList1.options[sObjList1.selectedIndex].text;
break;
}
// 連接源選擇框一選中項與源選擇框二選中項的文本
if( sObjList2.options[sObjList2.selectedIndex].text.indexOf("不限") >= 0 )
aText = sObjList2.options[sObjList2.selectedIndex].text;
else
aText = sObjList1.options[sObjList1.selectedIndex].text + joinchar + sObjList2.options[sObjList2.selectedIndex].text;
// 連接源選擇框一選中項與源選擇框二選中項的值
aValue = sObjList1.options[sObjList1.selectedIndex].value + joinchar + sObjList2.options[sObjList2.selectedIndex].value;
break;
case 2:
if( !enableoverlap && sObjList1.options[sObjList1.selectedIndex].text == sObjList2.options[sObjList2.selectedIndex].value)
{
aText = sObjList1.options[sObjList1.selectedIndex].text;
break;
}
aText = sObjList1.options[sObjList1.selectedIndex].text + joinchar + sObjList2.options[sObjList2.selectedIndex].value;
aValue = aText;
break;
// 組合類型四:目標列表框中項目的文本與值分別使用源選框中項目的文本與值,用兩個源選框中項目的值做重疊判斷
case 3:
// 不允許重疊,但源選擇框一選中項的值與源選擇框二選中項的值相同
if( !enableoverlap && sObjList1.options[sObjList1.selectedIndex].value == sObjList2.options[sObjList2.selectedIndex].value)
{
// 文本等于源選擇框二選中項的文本
aText = sObjList2.options[sObjList2.selectedIndex].text;
aValue = sObjList1.options[sObjList1.selectedIndex].value + joinchar;
alert(aValue);
alert(aText);
}
else
{
aText = sObjList1.options[sObjList1.selectedIndex].text + joinchar + sObjList2.options[sObjList2.selectedIndex].text;
aValue = sObjList1.options[sObjList1.selectedIndex].value + joinchar + sObjList2.options[sObjList2.selectedIndex].value;
}
break;
// 組合類型四:目標列表框中項目的文本與值均使用源選框中項目的值
case 4:
// 不允許重疊,但源選擇框一選中項的值與源選擇框二選中項的值相同
if( !enableoverlap && sObjList1.options[sObjList1.selectedIndex].value == sObjList2.options[sObjList2.selectedIndex].value)
{
// 文本等于值
aText = sObjList1.options[sObjList1.selectedIndex].value;
aValue = sObjList1.options[sObjList1.selectedIndex].value + joinchar;
}
else
{
aText = sObjList1.options[sObjList1.selectedIndex].value + sObjList2.options[sObjList2.selectedIndex].value;
aValue = sObjList1.options[sObjList1.selectedIndex].value + joinchar + sObjList2.options[sObjList2.selectedIndex].value;
}
break;
}
if( tObjList.length < limit || limit == 0 )
{
for( i=0; i<tObjList.length; i++ )
{
if( tObjList.options[i].text == aText )
return;
}
tObjList.options[tObjList.length] = new Option(aText, aValue);
tObjList.options[tObjList.length-1].selected = true;
}
}
}
}
function DeleteListSelectedItem(objListID, reserves)
{
var objList;
objList = document.getElementById(objListID);
if( objList != null )
{
if( objList.selectedIndex >= 0 )
{
if( objList.length > reserves )
objList.options[objList.selectedIndex] = null;
}
}
}
function NodeStateChange(nodeID, isLastNode)
{
var objNode1, objNode2;
objNode1 = document.getElementById(nodeID);
objNode2 = document.getElementById(nodeID + "_1");
if( (objNode1 != null) && (objNode2 != null) )
{
if( objNode2.className == "hidenode" )
{
objNode1.src = objNode1.src.replace("pnode.gif", "pnode_exp.gif");
objNode2.className = "";
}
else
{
objNode1.src = objNode1.src.replace("pnode_exp.gif", "pnode.gif");
objNode2.className = "hidenode";
}
}
}
// year, 年,數(shù)值
// month, 月,數(shù)值
// day, 日,選擇列表(Select)對象
function ChangeDate(year, month, day)
{
var daysPerMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var dispersion;
var aYear, aMonth, aDay;
aYear = parseInt(year);
aMonth = parseInt(month);
if( !isNaN(aYear) )
{
if( aYear % 4 == 0 )
{
daysPerMonth[2-1] = 29; // 閏年 2 月 29 天
}
}
if ( !isNaN(aMonth) && (aMonth <= 12) && day.options )
{
aMonth = aMonth - 1;
if( day.length != daysPerMonth[aMonth] ) // 列表天數(shù)與正確值不符
{
dispersion = day.length - daysPerMonth[aMonth]; // 計算差值
if( dispersion > 0 ) // 列表天數(shù)多
{
for( i=0; i<dispersion; i++ )
{
day.options[day.length-1] = null;
}
}
else // 列表天數(shù)少
{
dispersion = Math.abs(dispersion); // 計算差值
for( i=0; i<dispersion; i++ )
{
aDay = day.length + 1;
day.options[day.length] = new Option(aDay.toString(), aDay.toString());
}
}
}
}
}
function ShowAndHide(id1, id2)
{
var objElement1, objElement2;
objElement1 = document.getElementById(id1);
objElement2 = document.getElementById(id2);
if( objElement1 != null && objElement2 != null )
{
objElement1.style.display = "";
objElement2.style.display = "none";
}
}
function SelectAllItem(item)
{
if( typeof(item.length) == "undefined" )
{
item.checked = !item.checked
}
else
{
for(i=0;i<item.length;i++)
{
item[i].checked=!item[i].checked
}
}
}
function SelectAllOptions()
{
var aObject;
var returnResult = true;
for( i=0; i<arguments.length; i++ )
{
aObject = arguments[i];
if( aObject.length > 0 )
{
for(ii=0;ii<aObject.length;ii++)
{
if( !aObject.options[ii].selected )
aObject.options[ii].selected= true;
}
}
else
{
alert("請至少選擇一項!");
returnResult = false;
break;
}
}
return returnResult;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -