📄 cascadingutil.js
字号:
/**********************************************************************//**********************************************************************//******** ********//******** Cascading Select Util methods ********//******** =============================== ********//******** Author: Onyeje Bose (digi9ten@yahoo.com) ********//******** ********//**********************************************************************//**********************************************************************/ var pairs = new Map(); // caller and receiver pairs. /* temp map to be reused by the dynamic selects created later. */ var tmpMap; var tmpDataMap; /**************************************************************** Pairs Array Maniputlation ***************************************************************/ function getKeyForPair( callerName, receiverName ) { return ( callerName + "__" + receiverName ); } function getDataMapForPair( callerName, receiverName ) { return ( pairs.get( getKeyForPair( callerName, receiverName ) ) ); } function setDataMapForPair( callerName, receiverName, map ) { pairs.put( getKeyForPair( callerName, receiverName ), map ); } function addCallerReceiverPair( callerName, receiverName ) { pairs.put( getKeyForPair( callerName, receiverName ), new Map() ); } /**************************************************************** Receiver Select Maniputlation ***************************************************************/ function getKeyFromCaller( callerName ) { var caller = getElement( callerName ); return ( caller.options[ caller.selectedIndex ].value ); } function callerHasChanged( callerName, receiverName ) { var dataMap = getDataMapForPair( callerName, receiverName ); var tmp = dataMap.get( getKeyFromCaller( callerName ) ); if( tmp == null ) return; var tmpKeys = tmp.keySet(); var tmpVals = tmp.valSet(); clearList( receiverName ); for( var index = 0; index < tmp.size(); index++ ) { addNewOptionToTarget( receiverName, tmpVals[ index ], tmpKeys[ index ] ); } } function clearList( theListName ) { var theList = getElement( theListName ); var x = theList.length; while( x >= 0 ) { theList.options[ x-- ] = null; } } function addNewOptionToTarget( targetName, txt, val ) { var target = getElement( targetName ); target.options[ target.options.length ] = new Option( txt, val, false, false ); } function getElement( elmntName ) { var numberForms = document.forms.length; for ( var formIndex = 0; formIndex < numberForms; formIndex++ ) { var frm = document.forms[ formIndex ]; var numberElms = frm.elements.length; for (var elmIndex = 0; elmIndex < numberElms; elmIndex++ ) { if( elmntName == frm.elements[ elmIndex ].name ) { return frm.elements[ elmIndex ]; } } } return null; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -