?? dropdownlist.js
字號:
////////////////////////////////////////////////////////////////
//參數說明:
//參數 類型 含義
//theObj: String 選擇的控件名(多個以逗號隔開)
//theTable: String 確定數據庫表名
//theValueField: String 下拉列表行各列的值(逗號分隔)
//theTextField: String 下拉列表行各列的的顯示值,逗號分隔,如果與值相同就不要填寫,個數與值個數對應
//isHide String 是否隱藏,默認不隱藏,"Y"為隱藏,與值個數對應
//theWhere: String 確定檢索條件
//theQuery: String 確定檢索語句(與theTable是互斥)
//theTitle: String 對話窗口的標題
//itheRelateUrl: int 當前目錄相對于public的層數
////////////////////////////////////////////////////////////////
/**
* 普通的下拉列表,沒有隱藏列功能和智能匹配功能
* 智能匹配是指程序自動列出和頁面上的input元素的值(如果不空)相匹配的記錄
* 不要和下拉列表彈出后的動態搜索匹配相混淆。
*/
function dropDown(theObj,theTable,theValueField,theTextField,theWhere,theQuery,theTitle,itheRelateUrl)
{
var isHide="";
var sVal,sTxt;
sVal=theValueField+","+theTextField;
sTxt="";
if (itheRelateUrl==null || itheRelateUrl=="")
itheRelateUrl=2;
return dropDownOrg(theObj,theTable,sVal,sTxt,isHide,theWhere,theQuery,theTitle,itheRelateUrl,"");
}
/**
*完全控制下拉列表的功能
*/
function dropDown(theObj,theTable,theValueField,theTextField,isHide,theWhere,theQuery,theTitle,itheRelateUrl,isPart)
{
return dropDownOrg(theObj,theTable,theValueField,theTextField,isHide,theWhere,theQuery,theTitle,itheRelateUrl,isPart);
}
/**
* 沒有智能匹配功能
*/
function dropDownPart(theObj,theTable,theValueField,theTextField,isHide,theWhere,theQuery,theTitle,itheRelateUrl)
{
return dropDownOrg(theObj,theTable,theValueField,theTextField,isHide,theWhere,theQuery,theTitle,itheRelateUrl,"N");
}
function dropDownOrg(theObj,theTable,theValueField,theTextField,isHide,theWhere,theQuery,theTitle,itheRelateUrl,isPart)
{
var rc,i;
var asRs=new Array();
var asObj=new Array();
var Url,x,y,style,theValue,theParams,multiObj;
var aObjs=new Array();
var sObj1;
var sSelTxt="";
aObjs=theObj.split(",");
if (aObjs.length>1)
multiObj='Y';
else
multiObj='N';
sObj1=aObjs[0];
sSelTxt=window.document.getElementById(sObj1).value;
if (sSelTxt==null)
sSelTxt="";
if (window.document.getElementById(sObj1).className.toLowerCase()=="readonly")
return;
var temp="";
x=new String("");
y=new String("");
//得到彈出的位置
var ele;
ele=window.event.srcElement;
if(ele.tagName.toUpperCase()=="IMG" || ele.tagName.toUpperCase()=="DIV")
{
y=window.event.screenY;
x=window.event.screenX-100;
}else
{
x=getLeft(window.event.srcElement)+window.screenLeft+window.event.srcElement.offsetWidth/3;
y=getTop(window.event.srcElement)+window.screenTop+window.event.srcElement.offsetHeight/2;
}
if (theTable==null)
theTable="";
theTable=replaceTheChar(theTable,"/"," ");
if (theValueField==null)
theValueField="";
theValueField=replaceTheChar(theValueField,"/"," ");
if (theTextField==null)
theTextField="";
theTextField=replaceTheChar(theTextField,"/"," ");
if (theWhere==null)
theWhere="";
theWhere=replaceTheChar(theWhere,"/"," ");
theWhere=replaceTheChar(theWhere,"=","^");
theWhere=replaceTheChar(theWhere,"#","$");
theWhere=replaceTheChar(theWhere,"|","/");
if (theQuery==null)
theQuery="";
theQuery=replaceTheChar(theQuery,"=","^");
theQuery=replaceTheChar(theQuery,"#","$");
if (theTitle==null)
theTitle="";
theTitle=replaceTheChar(theTitle,"/"," ");
if (isHide==null)
isHide="";
if (isPart==null)
isPart="";
if (theTable=="" && theValueField=="" && theTextField=="" && theWhere=="" && theQuery=="")
{
alert("參數無效!\r\n,請檢查參數是否正確。");
return;
}
if (itheRelateUrl==null ||itheRelateUrl=="")
itheRelateUrl=2;
for (i=1;i<=itheRelateUrl;i++)
temp+="../";
Url=temp+"option/dropDownList.jsp";
theParams="?theTable="+theTable+"&theValueField="+theValueField;
theParams+="&theTextField="+theTextField+"&isHide="+isHide+"&theWhere="+theWhere;
theParams+="&theSQL="+theQuery+"&theTitle="+theTitle;
theParams+="&sSelTxt="+sSelTxt;
theParams+="&multiObj="+multiObj+"&isPart="+isPart;
Url+=theParams;
style="status:no;help:no;dialogWidth:1;dialogHeight:1;dialogTop:"+y+";dialogLeft:"+x;
theValue=window.showModalDialog(Url,null,style);
rc=(theValue==null)?"":theValue;
asRs=splitValue(rc);
asObj=theObj.split(",");
for(i=0;i<Math.min(asRs.length,asObj.length); i++)
{
window.document.getElementById(asObj[i]).value=asRs[i];
}
return asRs[0];
}
/**
* 調用檢驗函數的下拉列表
* anyChange是自定義函數,在列表值被選中之后,可以執行一些有效性檢測等操作
*/
function dropDownOnChg(func,theObj,theTable,theValueField,theTextField,isHide,theWhere,theQuery,theTitle,itheRelateUrl)
{
var rc,i;
var asRs=new Array();
var asObj=new Array();
var isPart = "N";
var Url,x,y,style,theValue,theParams,multiObj;
var aObjs=new Array();
var sObj1;
var sSelTxt="";
aObjs=theObj.split(",");
if (aObjs.length>1)
multiObj='Y';
else
multiObj='N';
sObj1=aObjs[0];
sSelTxt=window.document.getElementById(sObj1).value;
if (sSelTxt==null)
sSelTxt="";
if (window.document.getElementById(sObj1).className.toLowerCase()=="readonly")
return;
var temp="";
x=new String("");
y=new String("");
//得到彈出的位置
var ele;
ele=window.event.srcElement;
if(ele.tagName.toUpperCase()=="IMG" || ele.tagName.toUpperCase()=="DIV")
{
y=window.event.screenY;
x=window.event.screenX-100;
}else
{
x=getLeft(window.event.srcElement)+window.screenLeft+window.event.srcElement.offsetWidth/3;
y=getTop(window.event.srcElement)+window.screenTop+window.event.srcElement.offsetHeight/2;
}
if (theTable==null)
theTable="";
theTable=replaceTheChar(theTable,"/"," ");
if (theValueField==null)
theValueField="";
theValueField=replaceTheChar(theValueField,"/"," ");
if (theTextField==null)
theTextField="";
theTextField=replaceTheChar(theTextField,"/"," ");
if (theWhere==null)
theWhere="";
theWhere=replaceTheChar(theWhere,"/"," ");
theWhere=replaceTheChar(theWhere,"=","^");
theWhere=replaceTheChar(theWhere,"#","$");
theWhere=replaceTheChar(theWhere,"|","/");
if (theQuery==null)
theQuery="";
theQuery=replaceTheChar(theQuery,"=","^");
theQuery=replaceTheChar(theQuery,"#","$");
if (theTitle==null)
theTitle="";
theTitle=replaceTheChar(theTitle,"/"," ");
if (isHide==null)
isHide="";
if (isPart==null)
isPart="";
if (theTable=="" && theValueField=="" && theTextField=="" && theWhere=="" && theQuery=="")
{
alert("參數無效!\r\n,請檢查參數是否正確。");
return;
}
if (itheRelateUrl==null ||itheRelateUrl=="")
itheRelateUrl=2;
for (i=1;i<=itheRelateUrl;i++)
temp+="../";
Url=temp+"option/dropDownList.jsp";
theParams="?theTable="+theTable+"&theValueField="+theValueField;
theParams+="&theTextField="+theTextField+"&isHide="+isHide+"&theWhere="+theWhere;
theParams+="&theSQL="+theQuery+"&theTitle="+theTitle;
theParams+="&sSelTxt="+sSelTxt;
theParams+="&multiObj="+multiObj+"&isPart="+isPart;
Url+=theParams;
style="status:no;help:no;dialogWidth:1;dialogHeight:1;dialogTop:"+y+";dialogLeft:"+x;
theValue=window.showModalDialog(Url,null,style);
rc=(theValue==null)?"":theValue;
asRs=splitValue(rc);
asObj=theObj.split(",");
for(i=0;i<Math.min(asRs.length,asObj.length); i++)
{
window.document.getElementById(asObj[i]).value=asRs[i];
}
if (typeof func == "function")
{
this.doAnyChange = func;
this.doAnyChange();
}
return asRs[0];
}
/**
* 調用檢驗函數的下拉列表
* 在列表值被選中之后,執行全局的anyChanged()函數,需要用戶自定義
*/
function dropDownChg(theObj,theTable,theValueField,theTextField,isHide,theWhere,theQuery,theTitle,itheRelateUrl,isPart)
{
var rcOrg,rcNew,sObj1;
var aObj=new Array();
aObj=theObj.split(",");
sObj1=aObj[0];
rcOrg=document.getElementById(sObj1).value;
if (rcOrg==null)
rcOrg="";
rcNew=dropDownOrg(theObj,theTable,theValueField,theTextField,isHide,theWhere,theQuery,theTitle,itheRelateUrl,isPart);
if (rcOrg!=rcNew && rcNew!="" && rcNew!=null)
anyChanged();
return rcNew;
}
function replaceTheChar(theData,theOrginChar,thereplaceTheChar)
{
if (theData=="" || theData==null)
return theData;
while (theData.indexOf(theOrginChar)!=-1)
{
theData=theData.replace(theOrginChar,thereplaceTheChar);
}
return theData;
}
function splitValue(val)
{
//返回數組,輸入字符串以 分離
var rc,i,j,sp;
var as=new Array();
var asRs=new Array();
rc=val;
if (rc==null)
rc=" ";
sp=","+String.fromCharCode(160,160);
if(!(rc==""))
{
as=rc.split(sp);
//j=0;
for(i=0;i<as.length;i++)
{
//if(trimSp(as[i])=="") continue;
asRs[i]=trimSp(as[i]);
//j++;
}
}
return asRs;
}
function trimSp(theData)
{
var checkStr = theData;
if (checkStr=="")
return "";
var theStrLength=0;
while (checkStr.charAt(0)==" " || checkStr.charCodeAt(0)==160)
checkStr=checkStr.substring(1,checkStr.length);
theStrLength=checkStr.length;
while (checkStr.charAt(theStrLength-1)==" " || checkStr.charCodeAt(theStrLength-1)==160)
{
checkStr=checkStr.substring(0,checkStr.length-1);
theStrLength=checkStr.length
}
return checkStr;
}
function getTop(e)
{
var t=e.offsetTop;
while(e=e.offsetParent)
t+=e.offsetTop;
return t;
}
function getLeft(e)
{
var l=e.offsetLeft;
while(e=e.offsetParent)
l+=e.offsetLeft;
return l;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -