自定义标签的简单实用例子日期控件.docx
- 文档编号:30577866
- 上传时间:2023-08-16
- 格式:DOCX
- 页数:18
- 大小:20.71KB
自定义标签的简单实用例子日期控件.docx
《自定义标签的简单实用例子日期控件.docx》由会员分享,可在线阅读,更多相关《自定义标签的简单实用例子日期控件.docx(18页珍藏版)》请在冰豆网上搜索。
自定义标签的简单实用例子日期控件
1,首先建立配置文件afrom.tld
xmlversion="1.0"encoding="UTF-8"?
>
DOCTYPEtaglibPUBLIC"-//SunMicrosystems,Inc.//DTDJSPTagLibrary1.1//EN""
2,建立java类
packagepany.tag;
importjava.io.IOException;
importjavax.servlet.jsp.JspException;
importjavax.servlet.jsp.JspWriter;
importjavax.servlet.jsp.tagext.TagSupport;
publicclassDateTagextendsTagSupport{
privatestaticfinallongserialVersionUID=1L;
privateStringproperty;
privateStringsize;
privateStringstyle;
publicintdoStartTag()throwsJspException{
System.out.println("DateTagisstart");
JspWriterout=this.pageContext.getOut();
try{
StringBufferpropertys=newStringBuffer();
if(size!
=null&&!
"".endsWith(size)){
propertys.append("size='"+size+"'");
}
if(style!
=null&&!
"".endsWith(style)){
propertys.append("style='"+style+"'");
}
Stringproperty1=propertys.toString();
out.println("
out.println("
}catch(IOExceptione){
e.printStackTrace();
}
returnSKIP_BODY;
}
publicintdoEndTag()throwsJspException{
System.out.println("DateTagisover");
returnEVAL_PAGE;
}
publicStringgetProperty(){
returnproperty;
}
publicvoidsetProperty(Stringproperty){
this.property=property;
}
publicStringgetSize(){
returnsize;
}
publicvoidsetSize(Stringsize){
this.size=size;
}
publicStringgetStyle(){
returnstyle;
}
publicvoidsetStyle(Stringstyle){
this.style=style;
}
}
3,在webRoot下建立js文件夹
建立下面三个日期js
(1)calendar.script
vargdCtrl=newObject();
vargoSelectTag=newArray();
vargcGray="#666666";
vargcToggle="#7CD397";
vargcBG="";
varpreviousObject=null;
//
vargdCurDate=newDate();
vargiYear=gdCurDate.getFullYear();
vargiMonth=gdCurDate.getMonth()+1;
vargiDay=gdCurDate.getDate();
vargCalMode="";
vargCalDefDate="";
vardatatimebgcolor="";
varCAL_MODE_NOBLANK="2";
functiontd_onmouseover()
{
if(window.event.srcElement.tagName=="TD")
{
window.event.srcElement.className=datatimebgcolor;
window.event.srcElement.style.border="1pxsolid#000000";
window.event.cancelBubble=true;
}
}
functiontd_onmouseout()
{
window.event.srcElement.style.backgroundColor="";
window.event.srcElement.style.border="0pxsolid";
}
functionfSetDate(iYear,iMonth,iDay){
//VicPopCal.style.visibility="hidden";
if((iYear==0)&&(iMonth==0)&&(iDay==0)){
gdCtrl.value="";
}else{
iMonth=iMonth+100+"";
iMonth=iMonth.substring
(1);
iDay=iDay+100+"";
iDay=iDay.substring
(1);
gdCtrl.value=iYear+iMonth+iDay;
}
for(iingoSelectTag)
goSelectTag[i].style.visibility="visible";
goSelectTag.length=0;
window.returnValue=gdCtrl.value;
window.close();
}
functionHiddenDiv()
{
vari;
VicPopCal.style.visibility="hidden";
for(iingoSelectTag)
goSelectTag[i].style.visibility="visible";
goSelectTag.length=0;
}
functionfSetSelected(aCell){
variOffset=0;
variYear=parseInt(tbSelYear.value);
variMonth=parseInt(tbSelMonth.value);
aCell.bgColor=gcBG;
with(aCell.children["cellText"]){
variDay=parseInt(innerText);
if(color==gcGray)
iOffset=(Victor<10)?
-1:
1;
/***belowtemppatchbymaxiang***/
if(color==gcGray){
iOffset=(iDay<15)?
1:
-1;
}
/***abovetemppatchbymaxiang***/
iMonth+=iOffset;
if(iMonth<1){
iYear--;
iMonth=12;
}elseif(iMonth>12){
iYear++;
iMonth=1;
}
}
fSetDate(iYear,iMonth,iDay);
}
functionPoint(iX,iY){
this.x=iX;
this.y=iY;
}
functionfBuildCal(iYear,iMonth){
varaMonth=newArray();
for(i=1;i<7;i++)
aMonth[i]=newArray(i);
vardCalDate=newDate(iYear,iMonth-1,1);
variDayOfFirst=dCalDate.getDay();
variDaysInMonth=newDate(iYear,iMonth,0).getDate();
variOffsetLast=newDate(iYear,iMonth-1,0).getDate()-iDayOfFirst+1;
variDate=1;
variNext=1;
for(d=0;d<7;d++)
aMonth[1][d]=(d -(iOffsetLast+d): iDate++; for(w=2;w<7;w++) for(d=0;d<7;d++) aMonth[w][d]=(iDate<=iDaysInMonth)? iDate++: -(iNext++); returnaMonth; } functionfDrawCal(iYear,iMonth,iCellHeight,sDateTextSize){ varWeekDay=newArray("日","一","二","三","四","五","六"); varstyleTD="bgcolor='"+gcBG+"'bordercolor='"+gcBG+"'valign='middle'align='center'height='"+iCellHeight+"'"; with(document){ write(" for(i=0;i<7;i++) write(" #990099'>"+WeekDay[i]+" write(""); "); ");
for(w=1;w<7;w++){
write("
for(d=0;d<7;d++){
write(" hand;'onMouseOver='this.bgColor=gcToggle'onMouseOut='this.bgColor=gcBG'onclick='fSetSelected(this)'>"); write(" write("") } write("
}
}
}
functionfUpdateCal(iYear,iMonth){
myMonth=fBuildCal(iYear,iMonth);
vari=0;
for(w=0;w<6;w++)
for(d=0;d<7;d++)
with(cellText[(7*w)+d]){
Victor=i++;
if(myMonth[w+1][d]<0){
color=gcGray;
innerText=-myMonth[w+1][d];
}else{
//Modifiedbymaxiangforweneed
//Saturdaydisplayedinbluefontcolor.
//color=((d==0)||(d==6))?
"red":
"black";
if(d==0){
color="red";
}elseif(d==6){
color="red";
}else{
color="black";
}
//Endofabovemaxiang
innerText=myMonth[w+1][d];
}
}
}
functionfSetYearMon(iYear,iMon){
tbSelMonth.options[iMon-1].selected=true;
for(i=0;i if(tbSelYear.options[i].value==iYear) tbSelYear.options[i].selected=true; fUpdateCal(iYear,iMon); } functionfPrevMonth(){ variMon=tbSelMonth.value; variYear=tbSelYear.value; if(--iMon<1){ iMon=12; iYear--; } fSetYearMon(iYear,iMon); } functionfNextMonth(){ variMon=tbSelMonth.value; variYear=tbSelYear.value; if(++iMon>12){ iMon=1; iYear++; } fSetYearMon(iYear,iMon); } functionfToggleTags(){ with(document.all.tags("SELECT")){ for(i=0;i if((item(i).Victor! ="Won")&&fTagInBound(item(i))){ item(i).style.visibility="hidden"; goSelectTag[goSelectTag.length]=item(i); } } } functionfTagInBound(aTag){ with(VicPopCal.style){ varl=parseInt(left); vart=parseInt(top); varr=l+parseInt(width); varb=t+parseInt(height); varptLT=fGetXY(aTag); return! ((ptLT.x>r)||(ptLT.x+aTag.offsetWidth } } functionfGetXY(aTag){ varoTmp=aTag; varpt=newPoint(0,0); do{ pt.x+=oTmp.offsetLeft; pt.y+=oTmp.offsetTop; oTmp=oTmp.offsetParent; }while(oTmp.tagName! ="BODY"); returnpt; } //Main: popCtrlisthewidgetbeyondwhichyouwantthiscalendartoappear; //dateCtrlisthewidgetintowhichyouwanttoputtheselecteddate. //i.e.: center"readonly> functionfPopCalendar(popCtrl,dateCtrl,mode,defDate){ gCalMode=mode; gCalDefDate=defDate; if(popCtrl==previousObject){ if(VicPopCal.style.visibility=="visible"){ //HiddenDiv(); returntrue; } } previousObject=popCtrl; gdCtrl=dateCtrl; fSetYearMon(giYear,giMonth); varpoint=fGetXY(popCtrl); if(gCalMode==CAL_MODE_NOBLANK){ document.all.CAL_B_BLANK.style.visibility="hidden"; }else{ document.all.CAL_B_BLANK.style.visibility="visible"; } with(VicPopCal.style){ left=point.x; top=point.y+popCtrl.offsetHeight; width=VicPopCal.offsetWidth; height=VicPopCal.offsetHeight; fToggleTags(point); visibility='visible'; } } vargMonths=newArray("1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"); with(document){ write(" hidden;POSITION: absolute;VISIBILITY: hidden;border: 0pxridge;width: 100%;height: 100%;top: 0;left: 0;z-index: 100;overflow: hidden'>"); write(" 100%'align='center'>"); write(" write(" write(" 18px'onChange='fUpdateCal(tbSelYear.value,tbSelMonth.value)'Victor='Won'>"); for(i=1900;i<2100;i++) write(" write(""); write(" for(i=0;i<12;i++) write(" write(""); write(" write(""); write(" write(" write(" fDrawCal(giYear,giMonth,8,'12'); write(""); write(""); write("<"); ");
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 自定义 标签 简单 实用 例子 日期 控件