📄 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 + -