javascript

位置:IT落伍者 >> javascript >> 浏览文章

JS日期和时间选择控件升级版


发布日期:2024年03月11日
 
JS日期和时间选择控件升级版
鑒于网上找到的几个日期选择程序有些问题遂着手重写一个程序添加了时间选择功能截图及源码如下有需要的朋友可以参考下

鑒于网上找到的几个日期选择程序有些问题遂着手重写一个程序大部分还是借鑒前人的代码添加了时间选择功能隐藏会遮挡控件的标签selectobject
开始本想使用windowcreatePopup()来弹出日历的选择这样就可以跨过任何标签

不过做到中途发现用createPopup窗口实现理论上是行不通的
一是因为不在窗体里单击任何地方都会关闭窗口而当用下拉框选择年份时很有可能会单击到窗体外的地方当然这个可以自己写select来避免但是比较麻烦
二是窗体的宽度和高度只能在弹出时设置而显然在选择不同年月时控件高度是要发生改变的

鑒于上面的原因还是决定采用普通的处理方法

Calendarjs:

复制代码 代码如下:
/**
*本日历选择控件由tiannet根据前人经验完善而得大部分代码来自meizz的日历控件
*tiannet添加了时间选择功能selectobject标签隐藏功能还有其它小功能
*使用方法
* ()只选择日期 <input type="text" name="date" readOnly onClick="setDay(this);">
* ()选择日期和小时 <input type="text" name="dateh" readOnly onClick="setDayH(this);">
* ()选择日期和小时及分钟 <input type="text" name="datehm" readOnly onClick="setDayHM(this);">
*设置参数的方法
* ()设置日期分隔符 setDateSplit(strSplit);默认为""
* ()设置日期与时间之间的分隔符 setDateTimeSplit(strSplit);默认为" "
* ()设置时间分隔符 setTimeSplit(strSplit);默认为":"
* ()设置()()()中的分隔符 setSplit(strDateSplitstrDateTimeSplitstrTimeSplit);
* ()设置开始和结束年份 setYearPeriod(intDateBegintDateEnd)
*说明
* 默认返回的日期时间格式如同 :
*/
// 样式定义 //
//功能按钮同样样式
var s_tiannet_turn_base = "height:px;fontsize:pt;color:white;border: solid #CCCCCC;cursor:hand;backgroundcolor:#A;";
//翻年月等的按钮
var s_tiannet_turn = "width:px;" + s_tiannet_turn_base;
//关闭清空等按钮样式
var s_tiannet_turn = "width:px;" + s_tiannet_turn_base;
//年选择下拉框
var s_tiannet_select = "width:px;display:none;";
//月分选择下拉框
var s_tiannet_select = "width:px;display:none;";
//日期选择控件体的样式
var s_tiannet_body = "width:;backgroundcolor:#A;display:none;zindex:;position:absolute;" +
"borderleft: solid #CCCCCC;bordertop: solid #CCCCCC;borderright: solid #;borderbottom: solid #;";
//显示日的td的样式
var s_tiannet_day = "width:px;height:px;backgroundcolor:#DFFC;fontsize:pt;";
//字体样式
var s_tiannet_font = "color:#FFCC;fontsize:pt;cursor:hand;";
//链接的样式
var s_tiannet_link = "textdecoration:none;fontsize:pt;color:#A;";
//横线
var s_tiannet_line = "borderbottom: solid #CC";
// 变量定义 //
var tiannetYearSt = ;//可选择的开始年份
var tiannetYearEnd = ;//可选择的结束年份
var tiannetDateNow = new Date();
var tiannetYear = tiannetDateNowgetFullYear(); //定义年的变量的初始值
var tiannetMonth = tiannetDateNowgetMonth()+; //定义月的变量的初始值
var tiannetDay = tiannetDateNowgetDate();
var tiannetHour = ;//tiannetDateNowgetHours();
var tiannetMinute = ;//tiannetDateNowgetMinutes();
var tiannetArrDay=new Array(); //定义写日期的数组
var tiannetDateSplit = ""; //日期的分隔符号
var tiannetDateTimeSplit = " "; //日期与时间之间的分隔符
var tiannetTimeSplit = ":"; //时间的分隔符号
var tiannetOutObject; //接收日期时间的对象
var arrTiannetHide = new Array();//被强制隐藏的标签
var m_bolShowHour = false;//是否显示小时
var m_bolShowMinute = false;//是否显示分钟
var m_aMonHead = new Array(); //定义阳历中每个月的最大天数
m_aMonHead[] = ; m_aMonHead[] = ; m_aMonHead[] = ; m_aMonHead[] = ; m_aMonHead[] = ; m_aMonHead[] = ;
m_aMonHead[] = ; m_aMonHead[] = ; m_aMonHead[] = ; m_aMonHead[] = ; m_aMonHead[] = ; m_aMonHead[] = ;
// 用户可调用的函数 //
//用户主调函数-只选择日期
function setDay(obj){
tiannetOutObject = obj;
//如果标签中有值则将日期初始化为当前值
var strValue = tiannetTrim(tiannetOutObjectvalue);
if( strValue != "" ){
tiannetInitDate(strValue);
}
tiannetPopCalendar();
}
//用户主调函数-选择日期和小时
function setDayH(obj){
tiannetOutObject = obj;
m_bolShowHour = true;
//如果标签中有值则将日期和小时初始化为当前值
var strValue = tiannetTrim(tiannetOutObjectvalue);
if( strValue != "" ){
tiannetInitDate(strValuesubstring());
var hour = strValuesubstring();
if( hour < ) tiannetHour = hoursubstring();
}
tiannetPopCalendar();
}
//用户主调函数-选择日期和小时及分钟
function setDayHM(obj){
tiannetOutObject = obj;
m_bolShowHour = true;
m_bolShowMinute = true;
//如果标签中有值则将日期和小时及分钟初始化为当前值
var strValue = tiannetTrim(tiannetOutObjectvalue);
if( strValue != "" ){
tiannetInitDate(strValuesubstring());
var time = strValuesubstring();
var arr = timesplit(tiannetTimeSplit);
tiannetHour = arr[];
tiannetMinute = arr[];
if( tiannetHour < ) tiannetHour = tiannetHoursubstring();
if( tiannetMinute < ) tiannetMinute = tiannetMinutesubstring();
}
tiannetPopCalendar();
}
//设置开始日期和结束日期
function setYearPeriod(intDateBegintDateEnd){
tiannetYearSt = intDateBeg;
tiannetYearEnd = intDateEnd;
}
//设置日期分隔符默认为""
function setDateSplit(strDateSplit){
tiannetDateSplit = strDateSplit;
}
//设置日期与时间之间的分隔符默认为" "
function setDateTimeSplit(strDateTimeSplit){
tiannetDateTimeSplit = strDateTimeSplit;
}
//设置时间分隔符默认为":"
function setTimeSplit(strTimeSplit){
tiannetTimeSplit = strTimeSplit;
}
//设置分隔符
function setSplit(strDateSplitstrDateTimeSplitstrTimeSplit){
tiannetDateSplit(strDateSplit);
tiannetDateTimeSplit(strDateTimeSplit);
tiannetTimeSplit(strTimeSplit);
}
//设置默认的日期格式为YYYYMMDD
function setDefaultDate(strDate){
tiannetYear = strDatesubstring();
tiannetMonth = strDatesubstring();
tiannetDay = strDatesubstring();
}
//设置默认的时间格式为HH:MI
function setDefaultTime(strTime){
tiannetHour = strTimesubstring();
tiannetMinute = strTimesubstring();
}
// end 用户可调用的函数 //
// begin 页面显示部分 //
var weekName = new Array("日""一""二""三""四""五""六");
documentwrite(<div id="divTiannetDate" style="+s_tiannet_body+" style="本日历选择控件由tiannet根据前人经验完善而成!">);
documentwrite(<div align="center" id="divTiannetDateText" Author="tiannet" style="paddingtop:px;">);
documentwrite(<span id="tiannetYearHead" Author="tiannet" style="+s_tiannet_font+" +
onclick="spanYearCEvent();">年</span>);
documentwrite(<select id="selTianYear" style="+s_tiannet_select+" Author="tiannet" +
onChange="tiannetYear=thisvalue;tiannetSetDay(tiannetYeartiannetMonth);documentalltiannetYearHeadstyledisplay=\\;+
thisstyledisplay=\none\;">);
for(var i=tiannetYearSt;i <= tiannetYearEnd;i ++){
documentwriteln(<option value=" + i + "> + i + 年</option>);
}
documentwrite(</select>);
documentwrite(<span id="tiannetMonthHead" Author="tiannet" style="+s_tiannet_font+" +
onclick="spanMonthCEvent();">月</span>);
documentwrite(<select id="selTianMonth" style="+s_tiannet_select+" Author="tiannet" +
onChange="tiannetMonth=thisvalue;tiannetSetDay(tiannetYeartiannetMonth);documentalltiannetMonthHeadstyledisplay=\\;+
thisstyledisplay=\none\;">);
for(var i=;i <= ;i ++){
documentwriteln(<option value=" + i + "> + i + 月</option>);
}
documentwrite(</select>);
//documentwrite(</div>);
//documentwrite(<div align="center" id="divTiannetTimeText" Author="tiannet">);
documentwrite(<span id="tiannetHourHead" Author="tiannet" style="+s_tiannet_font+display:none;" +
onclick="spanHourCEvent();">时</span>);
documentwrite(<select id="selTianHour" style="+s_tiannet_select+display:none;" Author="tiannet" +
onChange="tiannetHour=thisvalue;tiannetWriteHead();documentalltiannetHourHeadstyledisplay=\\; +
thisstyledisplay=\none\;">);
for(var i=;i <= ;i ++){
documentwriteln(<option value=" + i + "> + i + 时</option>);
}
documentwrite(</select>);
documentwrite(<span id="tiannetMinuteHead" Author="tiannet" style="+s_tiannet_font+display:none;" +
onclick="spanMinuteCEvent();">分</span>);
documentwrite(<select id="selTianMinute" style="+s_tiannet_select+display:none;" Author="tiannet" +
onChange="tiannetMinute=thisvalue;tiannetWriteHead();documentalltiannetMinuteHeadstyledisplay=\\;+
thisstyledisplay=\none\;">);
for(var i=;i <= ;i ++){
documentwriteln(<option value=" + i + "> + i + 分</option>);
}
documentwrite(</select>);
documentwrite(</div>);
//输出一条横线
documentwrite(<div style="+s_tiannet_line+"></div>);
documentwrite(<div align="center" id="divTiannetTurn" style="border:;" Author="tiannet">);
documentwrite(<input type="button" style="+s_tiannet_turn+" value="年↑" title="上一年" onClick="tiannetPrevYear();">);
documentwrite(<input type="button" style="+s_tiannet_turn+" value="年↓" title="下一年" onClick="tiannetNextYear();">);
documentwrite(<input type="button" style="+s_tiannet_turn+" value="月↑" title="上一月" onClick="tiannetPrevMonth();">);
documentwrite(<input type="button" style="+s_tiannet_turn+" value="月↓" title="下一月" onClick="tiannetNextMonth();">);
documentwrite(</div>);
//输出一条横线
documentwrite(<div style="+s_tiannet_line+"></div>);
documentwrite(<table border= cellspacing= cellpadding= bgcolor=white onselectstart="return false">);
documentwrite( <tr style="backgroundcolor:#A;fontsize:pt;color:white;height:px;" Author="tiannet">);
for(var i =;i < weekNamelength;i ++){
//输出星期
documentwrite(<td width="" align="center" Author="tiannet"> + weekName[i] + </td>);
}
documentwrite( </tr>);
documentwrite(</table>);
//输出天的选择
documentwrite(<table border= cellspacing= cellpadding= bgcolor=white onselectstart="return false">);
var n = ;
for (var i=;i<;i++) {
documentwrite ( <tr align=center id="trTiannetDay + i + " >);
for (var j=;j<;j++){
documentwrite(<td align="center" id="tdTiannetDay + n + " +
onClick="tiannetDay=thisinnerText;tiannetSetValue(true);"
+ style=" + s_tiannet_day + "></td>);
n ++;
}
documentwrite ( </tr>);
}
documentwrite ( <tr align=center id="trTiannetDay" >);
documentwrite(<td align="center" id="tdTiannetDay" onClick="tiannetDay=thisinnerText;tiannetSetValue(true);"
+ style=" + s_tiannet_day + "></td>);
documentwrite(<td align="center" id="tdTiannetDay" onClick="tiannetDay=thisinnerText;tiannetSetValue(true);"
+ style=" + s_tiannet_day + "></td>);
documentwrite(<td  align="right" colspan=""><a href="javascript:tiannetClear();"  style=" + s_tiannet_link + ">清空</a>+
<a href="javascript:tiannetHideControl();" style=" + s_tiannet_link + ">关闭</a> +
<a href="javascript:tiannetSetValue(true);" style=" + s_tiannet_link + ">确定</a> +
</td>);
documentwrite ( </tr>);
documentwrite(</table>);
documentwrite(</div>);
// end 页面显示部分 //
// 显示日期时间的span标签响应事件 //
//单击年份span标签响应
function spanYearCEvent(){
hideElementsById(new Array("selTianYear""tiannetMonthHead")false);
if(m_bolShowHour) hideElementsById(new Array("tiannetHourHead")false);
if(m_bolShowMinute) hideElementsById(new Array("tiannetMinuteHead")false);
hideElementsById(new Array("tiannetYearHead""selTianMonth""selTianHour""selTianMinute")true);
}
//单击月份span标签响应
function spanMonthCEvent(){
hideElementsById(new Array("selTianMonth""tiannetYearHead")false);
if(m_bolShowHour) hideElementsById(new Array("tiannetHourHead")false);
if(m_bolShowMinute) hideElementsById(new Array("tiannetMinuteHead")false);
hideElementsById(new Array("tiannetMonthHead""selTianYear""selTianHour""selTianMinute")true);
}
//单击小时span标签响应
function spanHourCEvent(){
hideElementsById(new Array("tiannetYearHead""tiannetMonthHead")false);
if(m_bolShowHour) hideElementsById(new Array("selTianHour")false);
if(m_bolShowMinute) hideElementsById(new Array("tiannetMinuteHead")false);
hideElementsById(new Array("tiannetHourHead""selTianYear""selTianMonth""selTianMinute")true);
}
//单击分钟span标签响应
function spanMinuteCEvent(){
hideElementsById(new Array("tiannetYearHead""tiannetMonthHead")false);
if(m_bolShowHour) hideElementsById(new Array("tiannetHourHead")false);
if(m_bolShowMinute) hideElementsById(new Array("selTianMinute")false);
hideElementsById(new Array("tiannetMinuteHead""selTianYear""selTianMonth""selTianHour")true);
}
//根据标签id隐藏或显示标签
function hideElementsById(arrIdbolHide){
var strDisplay = "";
if(bolHide) strDisplay = "none";
for(var i = ;i < arrIdlength;i ++){
var obj = documentgetElementById(arrId[i]);
objstyledisplay = strDisplay;
}
}
// end 显示日期时间的span标签响应事件 //
//判断某年是否为闰年
function isPinYear(year){
var bolRet = false;
if (==year%&&((year%!=)||(year%==))) {
bolRet = true;
}
return bolRet;
}
//得到一个月的天数闰年为
function getMonthCount(yearmonth){
var c=m_aMonHead[month];
if((month==)&&isPinYear(year)) c++;
return c;
}
//重新设置当前的日主要是防止在翻年翻月时当前日大于当月的最大日
function setRealDayCount() {
if( tiannetDay > getMonthCount(tiannetYeartiannetMonth) ) {
//如果当前的日大于当月的最大日则取当月最大日
tiannetDay = getMonthCount(tiannetYeartiannetMonth);
}
}
//在个位数前加零
function addZero(value){
if(value < ){
value = "" + value;
}
return value;
}
//取出空格
function tiannetTrim(str) {
return strreplace(/(^\s*)|(\s*$)/g"");
}
//为select创建一个option
function createOption(objSelectvaluetext){
var option = documentcreateElement("OPTION");
optionvalue = value;
optiontext = text;
objSelectoptionsadd(option);
}
//往前翻 Year
function tiannetPrevYear() {
if(tiannetYear > && tiannetYear <){tiannetYear;}
else{alert("年份超出范围()!");}
tiannetSetDay(tiannetYeartiannetMonth);
//如果年份小于允许的最小年份则创建对应的option
if( tiannetYear < tiannetYearSt ) {
tiannetYearSt = tiannetYear;
createOption(documentallselTianYeartiannetYeartiannetYear + "年");
}
checkSelect(documentallselTianYeartiannetYear);
tiannetWriteHead();
}
//往后翻 Year
function tiannetNextYear() {
if(tiannetYear > && tiannetYear <){tiannetYear++;}
else{alert("年份超出范围()!");return;}
tiannetSetDay(tiannetYeartiannetMonth);
//如果年份超过允许的最大年份则创建对应的option
if( tiannetYear > tiannetYearEnd ) {
tiannetYearEnd = tiannetYear;
createOption(documentallselTianYeartiannetYeartiannetYear + "年");
}
checkSelect(documentallselTianYeartiannetYear);
tiannetWriteHead();
}
//选择今天
function tiannetToday() {
tiannetYear = tiannetDateNowgetFullYear();
tiannetMonth = tiannetDateNowgetMonth()+;
tiannetDay = tiannetDateNowgetDate();
tiannetSetValue(true);
//tiannetSetDay(tiannetYeartiannetMonth);
//selectObject();
}
//往前翻月份
function tiannetPrevMonth() {
if(tiannetMonth>){tiannetMonth}else{tiannetYear;tiannetMonth=;}
tiannetSetDay(tiannetYeartiannetMonth);
checkSelect(documentallselTianMonthtiannetMonth);
tiannetWriteHead();
}
//往后翻月份
function tiannetNextMonth() {
if(tiannetMonth==){tiannetYear++;tiannetMonth=}else{tiannetMonth++}
tiannetSetDay(tiannetYeartiannetMonth);
checkSelect(documentallselTianMonthtiannetMonth);
tiannetWriteHead();
}
//向span标签中写入年分等数据
function tiannetWriteHead(){
documentalltiannetYearHeadinnerText = tiannetYear + "年";
documentalltiannetMonthHeadinnerText = tiannetMonth + "月";
if( m_bolShowHour ) documentalltiannetHourHeadinnerText = " "+tiannetHour + "时";
if( m_bolShowMinute ) documentalltiannetMinuteHeadinnerText = tiannetMinute + "分";
tiannetSetValue(false);//给文本框赋值但不隐藏本控件
}
//设置显示天
function tiannetSetDay(yymm) {
setRealDayCount();//设置当月真实的日
tiannetWriteHead();
var strDateFont = "" strDateFont = "" //处理日期显示的风格
for (var i = ; i < ; i++){tiannetArrDay[i]=""}; //将显示框的内容全部清空
var day = ;
var firstday = new Date(yymm)getDay(); //某月第一天的星期几
for (var i = firstday; day < getMonthCount(yymm)+; i++){
tiannetArrDay[i]=day;day++;
}
//如果用于显示日的最后一行的第一个单元格的值为空则隐藏整行
//if(tiannetArrDay[] == ""){
// documentalltrTiannetDaystyledisplay = "none";
//} else {
// documentalltrTiannetDaystyledisplay = "";
//}
for (var i = ; i < ; i++){
var da = eval("documentalltdTiannetDay"+i) //书写新的一个月的日期星期排列
if (tiannetArrDay[i]!="") {
//判断是否为周末如果是周末则改为红色字体
if(i % == || (i+) % == ){
strDateFont = "<font color=#f>"
strDateFont = "</font>"
} else {
strDateFont = "";
strDateFont = ""
}
dainnerHTML = strDateFont + tiannetArrDay[i] + strDateFont;
//如果是当前选择的天则改变颜色
if(tiannetArrDay[i] == tiannetDay ) {
dastylebackgroundColor = "#CCCCCC";
} else {
dastylebackgroundColor = "#EFEFEF";
}
dastylecursor="hand"
} else {
dainnerHTML="";dastylebackgroundColor="";dastylecursor="default"
}
}//end for
tiannetSetValue(false);//给文本框赋值但不隐藏本控件
}//end function tiannetSetDay
//根据option的值选中option
function checkSelect(objSelectselectValue) {
var count = parseInt(objSelectlength);
if( selectValue < && selectValuetoString()length == ) {
selectValue = selectValuesubstring();
}
for(var i = ;i < count;i ++){
if(objSelectoptions[i]value == selectValue){
objSelectselectedIndex = i;
break;
}
}//for
}
//选中年分等下拉框
function selectObject(){
//如果年份小于允许的最小年份则创建对应的option
if( tiannetYear < tiannetYearSt ) {
for( var i = tiannetYear;i < tiannetYearSt;i ++ ){
createOption(documentallselTianYearii + "年");
}
tiannetYearSt = tiannetYear;
}
//如果年份超过允许的最大年份则创建对应的option
if( tiannetYear > tiannetYearEnd ) {
for( var i = tiannetYearEnd+;i <= tiannetYear;i ++ ){
createOption(documentallselTianYearii + "年");
}
tiannetYearEnd = tiannetYear;
}
checkSelect(documentallselTianYeartiannetYear);
checkSelect(documentallselTianMonthtiannetMonth);
if( m_bolShowHour ) checkSelect(documentallselTianHourtiannetHour);
if( m_bolShowMinute ) checkSelect(documentallselTianMinutetiannetMinute);
}
//给接受日期时间的控件赋值
//参数bolHideControl 是否隐藏控件
function tiannetSetValue(bolHideControl){
var value = "";
if( !tiannetDay || tiannetDay == "" ){
tiannetOutObjectvalue = value;
return;
}
var mm = tiannetMonth;
var day = tiannetDay;
if( mm < && mmtoString()length == ) mm = "" + mm;
if( day < && daytoString()length == ) day = "" + day;
value = tiannetYear + tiannetDateSplit + mm + tiannetDateSplit + day;
if( m_bolShowHour ){
var hour = tiannetHour;
if( hour < && hourtoString()length == ) hour = "" + hour;
value += tiannetDateTimeSplit + hour;
}
if( m_bolShowMinute ){
var minute = tiannetMinute;
if( minute < && minutetoString()length == ) minute = "" + minute;
value += tiannetTimeSplit + minute;
}
tiannetOutObjectvalue = value;
//documentalldivTiannetDatestyledisplay = "none";
if( bolHideControl ) {
tiannetHideControl();
}
}
//是否显示时间
function showTime(){
if( !m_bolShowHour && m_bolShowMinute){
alert("如果要选择分钟则必须可以选择小时!");
return;
}
hideElementsById(new Array("tiannetHourHead""selTianHour""tiannetMinuteHead""selTianMinute")true);
if( m_bolShowHour ){
//显示小时
hideElementsById(new Array("tiannetHourHead")false);
}
if( m_bolShowMinute ){
//显示分钟
hideElementsById(new Array("tiannetMinuteHead")false);
}
}
//弹出显示日历选择控件以让用户选择
function tiannetPopCalendar(){
//隐藏下拉框显示相对应的head
hideElementsById(new Array("selTianYear""selTianMonth""selTianHour""selTianMinute")true);
hideElementsById(new Array("tiannetYearHead""tiannetMonthHead""tiannetHourHead""tiannetMinuteHead")false);
tiannetSetDay(tiannetYeartiannetMonth);
tiannetWriteHead();
showTime();
var dads = documentalldivTiannetDatestyle;
var iX iY;
var h = documentalldivTiannetDateoffsetHeight;
var w = documentalldivTiannetDateoffsetWidth;
//计算left
if (windoweventx + h > documentbodyoffsetWidth )
iX = windoweventx h ;
else
iX = windoweventx + ;
if (iX <)
iX=;
//计算top
iY = windoweventy;
if (windoweventy + w > documentbodyoffsetHeight )
iY = documentbodyscrollTop + documentbodyoffsetHeight w ;
else
iY = documentbodyscrollTop +windoweventy + ;
if (iY <)
iY=;
dadsleft = iX;
dadstop = iY;
tiannetShowControl();
selectObject();
}
//隐藏日历控件(同时显示被强制隐藏的标签)
function tiannetHideControl(){
documentalldivTiannetDatestyledisplay = "none";
tiannetShowObject();
arrTiannetHide = new Array();//将被隐藏的标签对象清空
}
//显示日历控件(同时隐藏会遮挡的标签)
function tiannetShowControl(){
documentalldivTiannetDatestyledisplay = "";
tiannetHideObject("SELECT");
tiannetHideObject("OBJECT");
}
//根据标签名称隐藏标签如会遮住控件的selectobject
function tiannetHideObject(strTagName) {
x = documentalldivTiannetDateoffsetLeft;
y = documentalldivTiannetDateoffsetTop;
h = documentalldivTiannetDateoffsetHeight;
w = documentalldivTiannetDateoffsetWidth;
for (var i = ; i < documentalltags(strTagName)length; i++)
{
var obj = documentalltags(strTagName)[i];
if (! obj || ! objoffsetParent)
continue;
// 获取元素对于BODY标记的相对坐标
var objLeft = objoffsetLeft;
var objTop = objoffsetTop;
var objHeight = objoffsetHeight;
var objWidth = objoffsetWidth;
var objParent = objoffsetParent;
while (objParenttagNametoUpperCase() != "BODY"){
objLeft += objParentoffsetLeft;
objTop += objParentoffsetTop;
objParent = objParentoffsetParent;
}
//alert("控件左端:" + x + "select左端" + (objLeft + objWidth) + "控件底部:" + (y+h) + "select高:" + objTop);
var bolHide = true;
if( objstyledisplay == "none" || objstylevisibility == "hidden" || objgetAttribute("Author") == "tiannet" ){
//如果标签本身就是隐藏的则不需要再隐藏如果是控件中的下拉框也不用隐藏
bolHide = false;
}
if(  ( (objLeft + objWidth) > x && (y + h + ) > objTop  && (objTop+objHeight) > y && objLeft < (x+w) )  && bolHide ){
//arrTiannetHidepush(obj);//记录被隐藏的标签对象
arrTiannetHide[arrTiannetHidelength] = obj;
objstylevisibility = "hidden";
}
}
}
//显示被隐藏的标签
function tiannetShowObject(){
for(var i = ;i < arrTiannetHidelength;i ++){
//alert(arrTiannetHide[i]);
arrTiannetHide[i]stylevisibility = "";
}
}
//初始化日期
function tiannetInitDate(strDate){
var arr = strDatesplit(tiannetDateSplit);
tiannetYear = arr[];
tiannetMonth = arr[];
tiannetDay = arr[];
}
//清空
function tiannetClear(){
tiannetOutObjectvalue = "";
tiannetHideControl();
}
//任意点击时关闭该控件
function documentonclick(){
with(windoweventsrcElement){
if (tagName != "INPUT" && getAttribute("Author") != "tiannet")
tiannetHideControl();
}
}
//按ESC键关闭该控件
function documentonkeypress(){
if( eventkeyCode == ){
tiannetHideControl();
}
}


Calendarhtml:

复制代码 代码如下:


<!DOCTYPE HTML PUBLIC "//WC//DTD HTML Transitional//EN">
<html>
<head>
<title></title>
<meta name="GENERATOR" content="Microsoft Visual Studio NET ">
<meta name="ProgId" content="VisualStudioHTML">
<meta name="Originator" content="Microsoft Visual Studio NET ">
<script src="/Calendarjs"></script>
</head>
<body>
()只选择日期 <input type="text" name="date" readOnly onClick="setDay(this);"><br/>
()选择日期和小时 <input type="text" name="dateh" readOnly onClick="setDayH(this);"><br/>
()选择日期和小时及分钟 <input type="text" name="datehm" readOnly onClick="setDayHM(this);">
</body>
</html>

               

上一篇:JavaScript中几个重要的属性

下一篇:JavaScript获取FCK编辑器信息的具体方法