<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[沧海一粟]]></title> 
<link>http://www.dzhope.com/index.php</link> 
<description><![CDATA[Web系统架构与服务器运维,php开发]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[沧海一粟]]></copyright>
<item>
<link>http://www.dzhope.com/post//</link>
<title><![CDATA[javascript常用备忘]]></title> 
<author>jed &lt;jed521@163.com&gt;</author>
<category><![CDATA[代码编程]]></category>
<pubDate>Fri, 17 Nov 2006 06:29:29 +0000</pubDate> 
<guid>http://www.dzhope.com/post//</guid> 
<description>
<![CDATA[ 
	1、父子窗口<br/>打开一个子窗口：<br/> &lt;a href=&#039;#&#039; onClick=&#039;JavaScript:window.open(&quot;sub_win_name.html&quot;)&#039;&gt;open&lt;/a&gt;<br/><br/>打开即最大化：<br/> &lt;body onLoad=&quot;window.resizeTo(screen.width, screen.height);window.moveTo(0, 0);&quot;&gt;<br/> <br/><br/>得到父窗口的控件：<br/> window.opener.document.forms[0].txt1.value;<br/><br/>得到父窗口全局javascript变量：<br/> window.opener.var<br/><br/>刷新父页面：<br/> self.opener.location=&#039;url of super page&#039;<br/><br/>关闭窗口时，刷新父窗口：<br/> &lt;body onunload=&quot;opener.reload()&quot;&gt;<br/><br/>弹出对话框： <br/> window.alert();<br/> window.confirm()<br/> window.prompt()<br/> window.showModalDialog()<br/><br/>定时刷新窗口：<br/> &lt;body onload=&quot;setInterval(&#039;window.location.reload()&#039;,5000)&quot;&gt; <br/><br/>设定iframe的src：<br/> myIframe.src = &quot;the URL&quot;;<br/><br/>探测分辨率：<br/> screen.width<br/> screen.height<br/> &nbsp; <br/>2、控件<br/>遍历一个select（名为airline）：<br/> for(var j=0;j&lt;document.forms[0].airline.length;j++){<br/> &nbsp;if(document.forms[0].airline.options[j].text==&quot;&lt;%=airline%&gt;&quot;){<br/> &nbsp; document.forms[0].airline.selectedIndex = j;<br/> &nbsp;}<br/> }<br/>3、语言<br/>二维数组：<br/> var arr = new Array();<br/> for(var i=0;i&lt;3;i++){<br/> &nbsp;arr[i] = new Array();<br/> &nbsp;arr[i][0] = i+&quot;0&quot;;<br/> &nbsp;arr[i][1] = i+&quot;1&quot;;<br/> }<br/> <br/>4、其他：<br/>------------------------------------------------<br/><br/>如果你的网页设计了一个弹出窗口，发布一些消息什么的。将下面的代码加入适当<br/>位置，会使这个页面经过设置的时间后自动关闭。多实用呀！！！不会使弹出窗口功能<br/>招人嫌！本例设定10秒。<br/>将如下代码加入在规定时间自动关闭的页面HTML的&lt;HEAD&gt;区：<br/>&lt;script language=&quot;JavaScript&quot;&gt;<br/>function closeit() {<br/>setTimeout(&quot;self.close()&quot;,30000)<br/>}<br/>&lt;/script&gt;<br/>将如下代码加入在规定时间自动关闭的页面HTML的&lt;BODY&gt;区：<br/>&lt;body onload=&quot;closeit()&quot;&gt; &nbsp;*调用关闭脚本<br/><br/>--------------------------------------------------<br/>如何在JavaScript里定时触发一个函数调用？<br/><br/>setTimeout() 是延时**微秒之后执行，<br/>setInterval()是每隔**微秒执行一次<br/><br/>如果函数的最后一行是 setTimeout() 并执行自己，如：<br/>function abc() {<br/> &nbsp;... ...<br/> &nbsp;setTimeout(&quot;abc()&quot;, 100);<br/>}<br/><br/>执行的效果就和 setInterval(&quot;abc()&quot;, 100) 差不多了<br/><br/>-------------------------------------------------<br/>如何从父窗口定时关闭子窗口:<br/><br/>...<br/>&lt;script&gt;<br/>var hWnd=&#039;&#039;; //在function 外部声明全局变量,可以从父窗口访问子窗口变量，函数<br/>function myPopWindow(myURL){<br/> hWnd = window.open (myURL, &quot;popWin&quot;, &quot;width=780,height=560,top=0,left=0,resizable=no,scrollbars=yes&quot;);<br/> if ((document.window != null) &amp;&amp; (!hWnd.opener))<br/> &nbsp;hWnd.opener = document.window;<br/> hWnd.opener.focus();<br/> setTimeout(&#039;hWnd.window.close()&#039;, 1500);<br/>}<br/>&lt;/script&gt;<br/>...<br/>&lt;body bgcolor=&quot;#FFFFFF&quot; text=&quot;#000000&quot; onload=&quot;myPopWindow(&#039;http://someurl&#039;);&quot;&gt;<br/>...<br/><br/>---------------------------------------------------------------------------------------------------------<br/><br/>---------------------------------------------------------------------------------------------------------<br/><br/>一个日历：<br/><br/>使用：<br/><br/>&lt;input type=&quot;text&quot; name=&quot;beginDate&quot; size=&quot;12&quot; onfocus=&quot;calendar()&quot;&gt;<br/><br/>BUG：在frame中报错<br/><br/>解决：将这句parent.WebCalendar.wordColor的parent.去掉 <br/><br/>源代码：<br/><br/><br/>document.write(&quot;&lt;div id=meizzCalendarLayer style=&#039;position: absolute; z-index: 9999; width: 144; height: 193; display: none&#039;&gt;&quot;);<br/>document.write(&quot;&lt;iframe name=meizzCalendarIframe scrolling=no frameborder=0 width=100% height=100%&gt;&lt;/iframe&gt;&lt;/div&gt;&quot;);<br/>function writeIframe()<br/>{<br/> &nbsp; &nbsp;var strIframe = &quot;&lt;html&gt;&lt;head&gt;&lt;meta http-equiv=&#039;Content-Type&#039; content=&#039;text/html; charset=gb2312&#039;&gt;&lt;style&gt;&quot;+<br/> &nbsp; &nbsp;&quot;*{font-size: 12px; font-family: 宋体}&quot;+<br/> &nbsp; &nbsp;&quot;.bg{ &nbsp;color: &quot;+ WebCalendar.lightColor +&quot;; cursor: default; background-color: &quot;+ WebCalendar.darkColor +&quot;;}&quot;+<br/> &nbsp; &nbsp;&quot;table#tableMain{ width: 142; height: 180;}&quot;+<br/> &nbsp; &nbsp;&quot;table#tableWeek td{ color: &quot;+ WebCalendar.lightColor +&quot;;}&quot;+<br/> &nbsp; &nbsp;&quot;table#tableDay &nbsp;td{ font-weight: bold;}&quot;+<br/> &nbsp; &nbsp;&quot;td#meizzYearHead, td#meizzYearMonth{color: &quot;+ parent.WebCalendar.wordColor +&quot;}&quot;+<br/> &nbsp; &nbsp;&quot;.out { text-align: center; border-top: 1px solid &quot;+ WebCalendar.DarkBorder +&quot;; border-left: 1px solid &quot;+ WebCalendar.DarkBorder +&quot;;&quot;+<br/> &nbsp; &nbsp;&quot;border-right: 1px solid &quot;+ WebCalendar.lightColor +&quot;; border-bottom: 1px solid &quot;+ WebCalendar.lightColor +&quot;;}&quot;+<br/> &nbsp; &nbsp;&quot;.over{ text-align: center; border-top: 1px solid #FFFFFF; border-left: 1px solid #FFFFFF;&quot;+<br/> &nbsp; &nbsp;&quot;border-bottom: 1px solid &quot;+ WebCalendar.DarkBorder +&quot;; border-right: 1px solid &quot;+ WebCalendar.DarkBorder +&quot;}&quot;+<br/> &nbsp; &nbsp;&quot;input{ border: 1px solid &quot;+ WebCalendar.darkColor +&quot;; padding-top: 1px; height: 18; cursor: hand;&quot;+<br/> &nbsp; &nbsp;&quot; &nbsp; &nbsp; &nbsp; color:&quot;+ WebCalendar.wordColor +&quot;; background-color: &quot;+ WebCalendar.btnBgColor +&quot;}&quot;+<br/> &nbsp; &nbsp;&quot;&lt;/style&gt;&lt;/head&gt;&lt;body onselectstart=&#039;return false&#039; style=&#039;margin: 0px&#039; oncontextmenu=&#039;return false&#039;&gt;&lt;form name=meizz&gt;&quot;;<br/> &nbsp; &nbsp;if (WebCalendar.drag){ strIframe += &quot;&lt;scr&quot;+&quot;ipt language=javascript&gt;&quot;+<br/> &nbsp; &nbsp;&quot;var drag=false, cx=0, cy=0, o = parent.WebCalendar.calendar; function document.onmousemove(){&quot;+<br/> &nbsp; &nbsp;&quot;if(parent.WebCalendar.drag &amp;&amp; drag){if(o.style.left==&#039;&#039;)o.style.left=0; if(o.style.top==&#039;&#039;)o.style.top=0;&quot;+<br/> &nbsp; &nbsp;&quot;o.style.left = parseInt(o.style.left) + window.event.clientX-cx;&quot;+<br/> &nbsp; &nbsp;&quot;o.style.top &nbsp;= parseInt(o.style.top) &nbsp;+ window.event.clientY-cy;}}&quot;+<br/> &nbsp; &nbsp;&quot;function document.onkeydown(){ switch(window.event.keyCode){ &nbsp;case 27 : parent.hiddenCalendar(); break;&quot;+<br/> &nbsp; &nbsp;&quot;case 37 : parent.prevM(); break; case 38 : parent.prevY(); break; case 39 : parent.nextM(); break; case 40 : parent.nextY(); break;&quot;+<br/> &nbsp; &nbsp;&quot;case 84 : document.forms[0].today.click(); break;} window.event.keyCode = 0; window.event.returnValue= false;}&quot;+<br/> &nbsp; &nbsp;&quot;function dragStart(){cx=window.event.clientX; cy=window.event.clientY; drag=true;}&lt;/scr&quot;+&quot;ipt&gt;&quot;}<br/> &nbsp; &nbsp;strIframe += &quot;&lt;select name=tmpYearSelect &nbsp;onblur=&#039;parent.hiddenSelect(this)&#039; style=&#039;z-index:1;position:absolute;top:3;left:18;display:none&#039;&quot;+<br/> &nbsp; &nbsp;&quot; onchange=&#039;parent.WebCalendar.thisYear =this.value; parent.hiddenSelect(this); parent.writeCalendar();&#039;&gt;&lt;/select&gt;&quot;+<br/> &nbsp; &nbsp;&quot;&lt;select name=tmpMonthSelect onblur=&#039;parent.hiddenSelect(this)&#039; style=&#039;z-index:1; position:absolute;top:3;left:74;display:none&#039;&quot;+<br/> &nbsp; &nbsp;&quot; onchange=&#039;parent.WebCalendar.thisMonth=this.value; parent.hiddenSelect(this); parent.writeCalendar();&#039;&gt;&lt;/select&gt;&quot;+<br/> &nbsp; &nbsp;&quot;&lt;table id=tableMain class=bg border=0 cellspacing=2 cellpadding=0&gt;&quot;+<br/> &nbsp; &nbsp;&quot;&lt;tr&gt;&lt;td width=140 height=19 bgcolor=&#039;&quot;+ WebCalendar.lightColor +&quot;&#039;&gt;&quot;+<br/> &nbsp; &nbsp;&quot; &nbsp; &nbsp;&lt;table width=140 id=tableHead border=0 cellspacing=1 cellpadding=0&gt;&lt;tr align=center&gt;&quot;+<br/> &nbsp; &nbsp;&quot; &nbsp; &nbsp;&lt;td width=15 height=19 class=bg title=&#039;向前翻 1 月&amp;#13;快捷键：←&#039; style=&#039;cursor: hand&#039; onclick=&#039;parent.prevM()&#039;&gt;&lt;b&gt;&amp;lt;&lt;/b&gt;&lt;/td&gt;&quot;+<br/> &nbsp; &nbsp;&quot; &nbsp; &nbsp;&lt;td width=60 id=meizzYearHead &nbsp;title=&#039;点击此处选择年份&#039; onclick=&#039;parent.funYearSelect(parseInt(this.innerText, 10))&#039;&quot;+<br/> &nbsp; &nbsp;&quot; &nbsp; &nbsp; &nbsp; &nbsp;onmouseover=&#039;this.bgColor=parent.WebCalendar.darkColor; this.style.color=parent.WebCalendar.lightColor&#039;&quot;+<br/> &nbsp; &nbsp;&quot; &nbsp; &nbsp; &nbsp; &nbsp;onmouseout=&#039;this.bgColor=parent.WebCalendar.lightColor; this.style.color=parent.WebCalendar.wordColor&#039;&gt;&lt;/td&gt;&quot;+<br/> &nbsp; &nbsp;&quot; &nbsp; &nbsp;&lt;td width=50 id=meizzYearMonth title=&#039;点击此处选择月份&#039; onclick=&#039;parent.funMonthSelect(parseInt(this.innerText, 10))&#039;&quot;+<br/> &nbsp; &nbsp;&quot; &nbsp; &nbsp; &nbsp; &nbsp;onmouseover=&#039;this.bgColor=parent.WebCalendar.darkColor; this.style.color=parent.WebCalendar.lightColor&#039;&quot;+<br/> &nbsp; &nbsp;&quot; &nbsp; &nbsp; &nbsp; &nbsp;onmouseout=&#039;this.bgColor=parent.WebCalendar.lightColor; this.style.color=parent.WebCalendar.wordColor&#039;&gt;&lt;/td&gt;&quot;+<br/> &nbsp; &nbsp;&quot; &nbsp; &nbsp;&lt;td width=15 class=bg title=&#039;向后翻 1 月&amp;#13;快捷键：→&#039; onclick=&#039;parent.nextM()&#039; style=&#039;cursor: hand&#039;&gt;&lt;b&gt;&amp;gt;&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&quot;+<br/> &nbsp; &nbsp;&quot;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td height=20&gt;&lt;table id=tableWeek border=1 width=140 cellpadding=0 cellspacing=0 &quot;;<br/> &nbsp; &nbsp;if(WebCalendar.drag){strIframe += &quot;onmousedown=&#039;dragStart()&#039; onmouseup=&#039;drag=false&#039; onmouseout=&#039;drag=false&#039;&quot;;}<br/> &nbsp; &nbsp;strIframe += &quot; borderColorLight=&#039;&quot;+ WebCalendar.darkColor +&quot;&#039; borderColorDark=&#039;&quot;+ WebCalendar.lightColor +&quot;&#039;&gt;&quot;+<br/> &nbsp; &nbsp;&quot; &nbsp; &nbsp;&lt;tr align=center&gt;&lt;td height=20&gt;日&lt;/td&gt;&lt;td&gt;一&lt;/td&gt;&lt;td&gt;二&lt;/td&gt;&lt;td&gt;三&lt;/td&gt;&lt;td&gt;四&lt;/td&gt;&lt;td&gt;五&lt;/td&gt;&lt;td&gt;六&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&quot;+<br/> &nbsp; &nbsp;&quot;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=top width=140 bgcolor=&#039;&quot;+ WebCalendar.lightColor +&quot;&#039;&gt;&quot;+<br/> &nbsp; &nbsp;&quot; &nbsp; &nbsp;&lt;table id=tableDay height=120 width=140 border=0 cellspacing=1 cellpadding=0&gt;&quot;;<br/> &nbsp; &nbsp; &nbsp; &nbsp; for(var x=0; x&lt;5; x++){ strIframe += &quot;&lt;tr&gt;&quot;;<br/> &nbsp; &nbsp; &nbsp; &nbsp; for(var y=0; y&lt;7; y++) &nbsp;strIframe += &quot;&lt;td class=out id=&#039;meizzDay&quot;+ (x*7+y) +&quot;&#039;&gt;&lt;/td&gt;&quot;; strIframe += &quot;&lt;/tr&gt;&quot;;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; strIframe += &quot;&lt;tr&gt;&quot;;<br/> &nbsp; &nbsp; &nbsp; &nbsp; for(var x=35; x&lt;39; x++) strIframe += &quot;&lt;td class=out id=&#039;meizzDay&quot;+ x +&quot;&#039;&gt;&lt;/td&gt;&quot;;<br/> &nbsp; &nbsp; &nbsp; &nbsp; strIframe +=&quot;&lt;td colspan=3 class=out title=&#039;&quot;+ WebCalendar.regInfo +&quot;&#039;&gt;&lt;input style=&#039; background-color: &quot;+<br/> &nbsp; &nbsp; &nbsp; &nbsp; WebCalendar.btnBgColor +&quot;;cursor: hand; padding-top: 4px; width: 100%; height: 100%; border: 0&#039; onfocus=&#039;this.blur()&#039;&quot;+<br/> &nbsp; &nbsp; &nbsp; &nbsp; &quot; type=button value=&#039;&amp;nbsp; &amp;nbsp; 关闭&#039; onclick=&#039;parent.hiddenCalendar()&#039;&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&quot;+<br/> &nbsp; &nbsp;&quot;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td height=20 width=140 bgcolor=&#039;&quot;+ WebCalendar.lightColor +&quot;&#039;&gt;&quot;+<br/> &nbsp; &nbsp;&quot; &nbsp; &nbsp;&lt;table border=0 cellpadding=1 cellspacing=0 width=140&gt;&quot;+<br/> &nbsp; &nbsp;&quot; &nbsp; &nbsp;&lt;tr&gt;&lt;td&gt;&lt;input name=prevYear title=&#039;向前翻 1 年&amp;#13;快捷键：↑&#039; onclick=&#039;parent.prevY()&#039; type=button value=&#039;&amp;lt;&amp;lt;&#039;&quot;+<br/> &nbsp; &nbsp;&quot; &nbsp; &nbsp;onfocus=&#039;this.blur()&#039; style=&#039;meizz:expression(this.disabled=parent.WebCalendar.thisYear==1000)&#039;&gt;&lt;input&quot;+<br/> &nbsp; &nbsp;&quot; &nbsp; &nbsp;onfocus=&#039;this.blur()&#039; name=prevMonth title=&#039;向前翻 1 月&amp;#13;快捷键：←&#039; onclick=&#039;parent.prevM()&#039; type=button value=&#039;&amp;lt;&amp;nbsp;&#039;&gt;&quot;+<br/> &nbsp; &nbsp;&quot; &nbsp; &nbsp;&lt;/td&gt;&lt;td align=center&gt;&lt;input name=today type=button value=&#039;Today&#039; onfocus=&#039;this.blur()&#039; style=&#039;width: 50&#039; title=&#039;当前日期&amp;#13;快捷键：T&#039;&quot;+<br/> &nbsp; &nbsp;&quot; &nbsp; &nbsp;onclick=&#92;&quot;parent.returnDate(new Date().getDate() +&#039;/&#039;+ (new Date().getMonth() +1) +&#039;/&#039;+ new Date().getFullYear())&#92;&quot;&gt;&quot;+<br/> &nbsp; &nbsp;&quot; &nbsp; &nbsp;&lt;/td&gt;&lt;td align=right&gt;&lt;input title=&#039;向后翻 1 月&amp;#13;快捷键：→&#039; name=nextMonth onclick=&#039;parent.nextM()&#039; type=button value=&#039;&amp;nbsp;&amp;gt;&#039;&quot;+<br/> &nbsp; &nbsp;&quot; &nbsp; &nbsp;onfocus=&#039;this.blur()&#039;&gt;&lt;input name=nextYear title=&#039;向后翻 1 年&amp;#13;快捷键：↓&#039; onclick=&#039;parent.nextY()&#039; type=button value=&#039;&amp;gt;&amp;gt;&#039;&quot;+<br/> &nbsp; &nbsp;&quot; &nbsp; &nbsp;onfocus=&#039;this.blur()&#039; style=&#039;meizz:expression(this.disabled=parent.WebCalendar.thisYear==9999)&#039;&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&quot;+<br/> &nbsp; &nbsp;&quot;&lt;/td&gt;&lt;/tr&gt;&lt;table&gt;&lt;/form&gt;&lt;/body&gt;&lt;/html&gt;&quot;;<br/> &nbsp; &nbsp;with(WebCalendar.iframe)<br/> &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp;document.writeln(strIframe); document.close();<br/> &nbsp; &nbsp; &nbsp; &nbsp;for(var i=0; i&lt;39; i++)<br/> &nbsp; &nbsp; &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WebCalendar.dayObj[i] = eval(&quot;meizzDay&quot;+ i);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WebCalendar.dayObj[i].onmouseover = dayMouseOver;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WebCalendar.dayObj[i].onmouseout &nbsp;= dayMouseOut;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WebCalendar.dayObj[i].onclick &nbsp; &nbsp; = returnDate;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp;}<br/>}<br/>function WebCalendar() //初始化日历的设置<br/>{<br/> &nbsp; &nbsp;this.regInfo &nbsp; &nbsp;= &quot;WEB Calendar ver 3.0&amp;#13;作者：meizz(梅花雪疏影横斜)&amp;#13;网站：http://www.meizz.com/&amp;#13;关闭的快捷键：[Esc]&quot;;<br/> &nbsp; &nbsp;this.regInfo &nbsp; += &quot;&amp;#13;&amp;#13;Ver 2.0：walkingpoison(水晶龙)&amp;#13;Ver 1.0：meizz(梅花雪疏影横斜)&quot;;<br/> &nbsp; &nbsp;this.daysMonth &nbsp;= new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);<br/> &nbsp; &nbsp;this.day &nbsp; &nbsp; &nbsp; &nbsp;= new Array(39); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//定义日历展示用的数组<br/> &nbsp; &nbsp;this.dayObj &nbsp; &nbsp; = new Array(39); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//定义日期展示控件数组<br/> &nbsp; &nbsp;this.dateStyle &nbsp;= null; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //保存格式化后日期数组<br/> &nbsp; &nbsp;this.objExport &nbsp;= null; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //日历回传的显示控件<br/> &nbsp; &nbsp;this.eventSrc &nbsp; = null; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //日历显示的触发控件<br/> &nbsp; &nbsp;this.inputDate &nbsp;= null; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //转化外的输入的日期(d/m/yyyy)<br/> &nbsp; &nbsp;this.thisYear &nbsp; = new Date().getFullYear(); //定义年的变量的初始值<br/> &nbsp; &nbsp;this.thisMonth &nbsp;= new Date().getMonth()+ 1; //定义月的变量的初始值<br/> &nbsp; &nbsp;this.thisDay &nbsp; &nbsp;= new Date().getDate(); &nbsp; &nbsp; //定义日的变量的初始值<br/> &nbsp; &nbsp;this.today &nbsp; &nbsp; &nbsp;= this.thisDay +&quot;/&quot;+ this.thisMonth +&quot;/&quot;+ this.thisYear; &nbsp; //今天(d/m/yyyy)<br/> &nbsp; &nbsp;this.iframe &nbsp; &nbsp; = window.frames(&quot;meizzCalendarIframe&quot;); //日历的 iframe 载体<br/> &nbsp; &nbsp;this.calendar &nbsp; = getObjectById(&quot;meizzCalendarLayer&quot;); &nbsp;//日历的层<br/> &nbsp; &nbsp;this.dateReg &nbsp; &nbsp;= &quot;&quot;; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //日历格式验证的正则式<br/> &nbsp; &nbsp;this.yearFall &nbsp; = 50; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //定义年下拉框的年差值<br/> &nbsp; &nbsp;this.format &nbsp; &nbsp; = &quot;yyyy-mm-dd&quot;; //回传日期的格式<br/> &nbsp; &nbsp;this.timeShow &nbsp; = false; &nbsp; &nbsp; &nbsp; &nbsp;//是否返回时间<br/> &nbsp; &nbsp;this.drag &nbsp; &nbsp; &nbsp; = true; &nbsp; &nbsp; &nbsp; &nbsp; //是否允许拖动<br/> &nbsp; &nbsp;this.darkColor &nbsp;= &quot;#0000D0&quot;; &nbsp; &nbsp;//控件的暗色<br/> &nbsp; &nbsp;this.lightColor = &quot;#FFFFFF&quot;; &nbsp; &nbsp;//控件的亮色<br/> &nbsp; &nbsp;this.btnBgColor = &quot;#E6E6FA&quot;; &nbsp; &nbsp;//控件的按钮背景色<br/> &nbsp; &nbsp;this.wordColor &nbsp;= &quot;#000080&quot;; &nbsp; &nbsp;//控件的文字颜色<br/> &nbsp; &nbsp;this.wordDark &nbsp; = &quot;#DCDCDC&quot;; &nbsp; &nbsp;//控件的暗文字颜色<br/> &nbsp; &nbsp;this.dayBgColor = &quot;#F5F5FA&quot;; &nbsp; &nbsp;//日期数字背景色<br/> &nbsp; &nbsp;this.todayColor = &quot;#FF0000&quot;; &nbsp; &nbsp;//今天在日历上的标示背景色<br/> &nbsp; &nbsp;this.DarkBorder = &quot;#D4D0C8&quot;; &nbsp; &nbsp;//日期显示的立体表达色<br/>} &nbsp; var WebCalendar = new WebCalendar();<br/>function calendar() //主调函数<br/>{<br/> &nbsp; &nbsp;var e = window.event.srcElement; &nbsp; writeIframe();<br/> &nbsp; &nbsp;var o = WebCalendar.calendar.style; WebCalendar.eventSrc = e;<br/> if (arguments.length == 0) WebCalendar.objExport = e;<br/> &nbsp; &nbsp;else WebCalendar.objExport = eval(arguments[0]);<br/> &nbsp; &nbsp;WebCalendar.iframe.tableWeek.style.cursor = WebCalendar.drag ? &quot;move&quot; : &quot;default&quot;;<br/> var t = e.offsetTop, &nbsp;h = e.clientHeight, l = e.offsetLeft, p = e.type;<br/> while (e = e.offsetParent){t += e.offsetTop; l += e.offsetLeft;}<br/> &nbsp; &nbsp;o.display = &quot;&quot;; WebCalendar.iframe.document.body.focus();<br/> &nbsp; &nbsp;var cw = WebCalendar.calendar.clientWidth, ch = WebCalendar.calendar.clientHeight;<br/> &nbsp; &nbsp;var dw = document.body.clientWidth, dl = document.body.scrollLeft, dt = document.body.scrollTop;<br/> &nbsp; &nbsp;<br/> &nbsp; &nbsp;if (document.body.clientHeight + dt - t - h &gt;= ch) o.top = (p==&quot;image&quot;)? t + h : t + h + 6;<br/> &nbsp; &nbsp;else o.top &nbsp;= (t - dt &lt; ch) ? ((p==&quot;image&quot;)? t + h : t + h + 6) : t - ch;<br/> &nbsp; &nbsp;if (dw + dl - l &gt;= cw) o.left = l; else o.left = (dw &gt;= cw) ? dw - cw + dl : dl;<br/> &nbsp; &nbsp;if &nbsp;(!WebCalendar.timeShow) WebCalendar.dateReg = /^(&#92;d{1,4})(-&#124;&#92;/)(&#92;d{1,2})&#92;2(&#92;d{1,2})$/;<br/> &nbsp; &nbsp;else WebCalendar.dateReg = /^(&#92;d{1,4})(-&#124;&#92;/)(&#92;d{1,2})&#92;2(&#92;d{1,2}) (&#92;d{1,2}):(&#92;d{1,2}):(&#92;d{1,2})$/;<br/> &nbsp; &nbsp;try{<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (WebCalendar.objExport.value.trim() != &quot;&quot;){<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WebCalendar.dateStyle = WebCalendar.objExport.value.trim().match(WebCalendar.dateReg);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (WebCalendar.dateStyle == null)<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WebCalendar.thisYear &nbsp; = new Date().getFullYear();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WebCalendar.thisMonth &nbsp;= new Date().getMonth()+ 1;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WebCalendar.thisDay &nbsp; &nbsp;= new Date().getDate();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;alert(&quot;原文本框里的日期有错误！&#92;n可能与你定义的显示时分秒有冲突！&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;writeCalendar(); return false;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WebCalendar.thisYear &nbsp; = parseInt(WebCalendar.dateStyle[1], 10);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WebCalendar.thisMonth &nbsp;= parseInt(WebCalendar.dateStyle[3], 10);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WebCalendar.thisDay &nbsp; &nbsp;= parseInt(WebCalendar.dateStyle[4], 10);<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WebCalendar.inputDate &nbsp;= parseInt(WebCalendar.thisDay, 10) +&quot;/&quot;+ parseInt(WebCalendar.thisMonth, 10) +&quot;/&quot;+ <br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;parseInt(WebCalendar.thisYear, 10); writeCalendar();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;} &nbsp;else writeCalendar();<br/> &nbsp; &nbsp;} &nbsp;catch(e){writeCalendar();}<br/>}<br/>function funMonthSelect() //月份的下拉框<br/>{<br/> &nbsp; &nbsp;var m = isNaN(parseInt(WebCalendar.thisMonth, 10)) ? new Date().getMonth() + 1 : parseInt(WebCalendar.thisMonth);<br/> &nbsp; &nbsp;var e = WebCalendar.iframe.document.forms[0].tmpMonthSelect;<br/> &nbsp; &nbsp;for (var i=1; i&lt;13; i++) e.options.add(new Option(i +&quot;月&quot;, i));<br/> &nbsp; &nbsp;e.style.display = &quot;&quot;; e.value = m; e.focus(); window.status = e.style.top;<br/>}<br/>function funYearSelect() //年份的下拉框<br/>{<br/> &nbsp; &nbsp;var n = WebCalendar.yearFall;<br/> &nbsp; &nbsp;var e = WebCalendar.iframe.document.forms[0].tmpYearSelect;<br/> &nbsp; &nbsp;var y = isNaN(parseInt(WebCalendar.thisYear, 10)) ? new Date().getFullYear() : parseInt(WebCalendar.thisYear);<br/> &nbsp; &nbsp; &nbsp; &nbsp;y = (y &lt;= 1000)? 1000 : ((y &gt;= 9999)? 9999 : y);<br/> &nbsp; &nbsp;var min = (y - n &gt;= 1000) ? y - n : 1000;<br/> &nbsp; &nbsp;var max = (y + n &lt;= 9999) ? y + n : 9999;<br/> &nbsp; &nbsp; &nbsp; &nbsp;min = (max == 9999) ? max-n*2 : min;<br/> &nbsp; &nbsp; &nbsp; &nbsp;max = (min == 1000) ? min+n*2 : max;<br/> &nbsp; &nbsp;for (var i=min; i&lt;=max; i++) e.options.add(new Option(i +&quot;年&quot;, i));<br/> &nbsp; &nbsp;e.style.display = &quot;&quot;; e.value = y; e.focus();<br/>}<br/>function prevM() &nbsp;//往前翻月份<br/>{<br/> &nbsp; &nbsp;WebCalendar.thisDay = 1;<br/> &nbsp; &nbsp;if (WebCalendar.thisMonth==1)<br/> &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp;WebCalendar.thisYear--;<br/> &nbsp; &nbsp; &nbsp; &nbsp;WebCalendar.thisMonth=13;<br/> &nbsp; &nbsp;}<br/> &nbsp; &nbsp;WebCalendar.thisMonth--; writeCalendar();<br/>}<br/>function nextM() &nbsp;//往后翻月份<br/>{<br/> &nbsp; &nbsp;WebCalendar.thisDay = 1;<br/> &nbsp; &nbsp;if (WebCalendar.thisMonth==12)<br/> &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp;WebCalendar.thisYear++;<br/> &nbsp; &nbsp; &nbsp; &nbsp;WebCalendar.thisMonth=0;<br/> &nbsp; &nbsp;}<br/> &nbsp; &nbsp;WebCalendar.thisMonth++; writeCalendar();<br/>}<br/>function prevY(){WebCalendar.thisDay = 1; WebCalendar.thisYear--; writeCalendar();}//往前翻 Year<br/>function nextY(){WebCalendar.thisDay = 1; WebCalendar.thisYear++; writeCalendar();}//往后翻 Year<br/>function hiddenSelect(e){for(var i=e.options.length; i&gt;-1; i--)e.options.remove(i); e.style.display=&quot;none&quot;;}<br/>function getObjectById(id){ if(document.all) return(eval(&quot;document.all.&quot;+ id)); return(eval(id)); }<br/>function hiddenCalendar(){getObjectById(&quot;meizzCalendarLayer&quot;).style.display = &quot;none&quot;;};<br/>function appendZero(n){return((&quot;00&quot;+ n).substr((&quot;00&quot;+ n).length-2));}//日期自动补零程序<br/>function String.prototype.trim(){return this.replace(/(^&#92;s*)&#124;(&#92;s*$)/g,&quot;&quot;);}<br/>function dayMouseOver()<br/>{<br/> &nbsp; &nbsp;this.className = &quot;over&quot;;<br/> &nbsp; &nbsp;this.style.backgroundColor = WebCalendar.darkColor;<br/> &nbsp; &nbsp;if(WebCalendar.day[this.id.substr(8)].split(&quot;/&quot;)[1] == WebCalendar.thisMonth)<br/> &nbsp; &nbsp;this.style.color = WebCalendar.lightColor;<br/>}<br/>function dayMouseOut()<br/>{<br/> &nbsp; &nbsp;this.className = &quot;out&quot;; var d = WebCalendar.day[this.id.substr(8)], a = d.split(&quot;/&quot;);<br/> &nbsp; &nbsp;this.style.removeAttribute(&#039;backgroundColor&#039;);<br/> &nbsp; &nbsp;if(a[1] == WebCalendar.thisMonth &amp;&amp; d != WebCalendar.today)<br/> &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp;if(WebCalendar.dateStyle &amp;&amp; a[0] == parseInt(WebCalendar.dateStyle[4], 10))<br/> &nbsp; &nbsp; &nbsp; &nbsp;this.style.color = WebCalendar.lightColor;<br/> &nbsp; &nbsp; &nbsp; &nbsp;this.style.color = WebCalendar.wordColor;<br/> &nbsp; &nbsp;}<br/>}<br/>function writeCalendar() //对日历显示的数据的处理程序<br/>{<br/> &nbsp; &nbsp;var y = WebCalendar.thisYear;<br/> &nbsp; &nbsp;var m = WebCalendar.thisMonth; <br/> &nbsp; &nbsp;var d = WebCalendar.thisDay;<br/> &nbsp; &nbsp;WebCalendar.daysMonth[1] = (0==y%4 &amp;&amp; (y%100!=0 &#124;&#124; y%400==0)) ? 29 : 28;<br/> &nbsp; &nbsp;if (!(y&lt;=9999 &amp;&amp; y &gt;= 1000 &amp;&amp; parseInt(m, 10)&gt;0 &amp;&amp; parseInt(m, 10)&lt;13 &amp;&amp; parseInt(d, 10)&gt;0)){<br/> &nbsp; &nbsp; &nbsp; &nbsp;alert(&quot;对不起，你输入了错误的日期！&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp;WebCalendar.thisYear &nbsp; = new Date().getFullYear();<br/> &nbsp; &nbsp; &nbsp; &nbsp;WebCalendar.thisMonth &nbsp;= new Date().getMonth()+ 1;<br/> &nbsp; &nbsp; &nbsp; &nbsp;WebCalendar.thisDay &nbsp; &nbsp;= new Date().getDate(); }<br/> &nbsp; &nbsp;y = WebCalendar.thisYear;<br/> &nbsp; &nbsp;m = WebCalendar.thisMonth;<br/> &nbsp; &nbsp;d = WebCalendar.thisDay;<br/> &nbsp; &nbsp;WebCalendar.iframe.meizzYearHead.innerText &nbsp;= y +&quot; 年&quot;;<br/> &nbsp; &nbsp;WebCalendar.iframe.meizzYearMonth.innerText = parseInt(m, 10) +&quot; 月&quot;;<br/> &nbsp; &nbsp;WebCalendar.daysMonth[1] = (0==y%4 &amp;&amp; (y%100!=0 &#124;&#124; y%400==0)) ? 29 : 28; //闰年二月为29天<br/> &nbsp; &nbsp;var w = new Date(y, m-1, 1).getDay();<br/> &nbsp; &nbsp;var prevDays = m==1 &nbsp;? WebCalendar.daysMonth[11] : WebCalendar.daysMonth[m-2];<br/> &nbsp; &nbsp;for(var i=(w-1); i&gt;=0; i--) //这三个 for 循环为日历赋数据源（数组 WebCalendar.day）格式是 d/m/yyyy<br/> &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp;WebCalendar.day[i] = prevDays +&quot;/&quot;+ (parseInt(m, 10)-1) +&quot;/&quot;+ y;<br/> &nbsp; &nbsp; &nbsp; &nbsp;if(m==1) WebCalendar.day[i] = prevDays +&quot;/&quot;+ 12 +&quot;/&quot;+ (parseInt(y, 10)-1);<br/> &nbsp; &nbsp; &nbsp; &nbsp;prevDays--;<br/> &nbsp; &nbsp;}<br/> &nbsp; &nbsp;for(var i=1; i&lt;=WebCalendar.daysMonth[m-1]; i++) WebCalendar.day[i+w-1] = i +&quot;/&quot;+ m +&quot;/&quot;+ y;<br/> &nbsp; &nbsp;for(var i=1; i&lt;39-w-WebCalendar.daysMonth[m-1]+1; i++)<br/> &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp;WebCalendar.day[WebCalendar.daysMonth[m-1]+w-1+i] = i +&quot;/&quot;+ (parseInt(m, 10)+1) +&quot;/&quot;+ y;<br/> &nbsp; &nbsp; &nbsp; &nbsp;if(m==12) WebCalendar.day[WebCalendar.daysMonth[m-1]+w-1+i] = i +&quot;/&quot;+ 1 +&quot;/&quot;+ (parseInt(y, 10)+1);<br/> &nbsp; &nbsp;}<br/> &nbsp; &nbsp;for(var i=0; i&lt;39; i++) &nbsp; &nbsp;//这个循环是根据源数组写到日历里显示<br/> &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp;var a = WebCalendar.day[i].split(&quot;/&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp;WebCalendar.dayObj[i].innerText &nbsp; &nbsp;= a[0];<br/> &nbsp; &nbsp; &nbsp; &nbsp;WebCalendar.dayObj[i].title &nbsp; &nbsp; &nbsp; &nbsp;= a[2] +&quot;-&quot;+ appendZero(a[1]) +&quot;-&quot;+ appendZero(a[0]);<br/> &nbsp; &nbsp; &nbsp; &nbsp;WebCalendar.dayObj[i].bgColor &nbsp; &nbsp; &nbsp;= WebCalendar.dayBgColor;<br/> &nbsp; &nbsp; &nbsp; &nbsp;WebCalendar.dayObj[i].style.color &nbsp;= WebCalendar.wordColor;<br/> &nbsp; &nbsp; &nbsp; &nbsp;if ((i&lt;10 &amp;&amp; parseInt(WebCalendar.day[i], 10)&gt;20) &#124;&#124; (i&gt;27 &amp;&amp; parseInt(WebCalendar.day[i], 10)&lt;12))<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WebCalendar.dayObj[i].style.color = WebCalendar.wordDark;<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (WebCalendar.inputDate==WebCalendar.day[i]) &nbsp; &nbsp;//设置输入框里的日期在日历上的颜色<br/> &nbsp; &nbsp; &nbsp; &nbsp;{WebCalendar.dayObj[i].bgColor = WebCalendar.darkColor; WebCalendar.dayObj[i].style.color = WebCalendar.lightColor;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;if (WebCalendar.day[i] == WebCalendar.today) &nbsp; &nbsp; &nbsp;//设置今天在日历上反应出来的颜色<br/> &nbsp; &nbsp; &nbsp; &nbsp;{WebCalendar.dayObj[i].bgColor = WebCalendar.todayColor; WebCalendar.dayObj[i].style.color = WebCalendar.lightColor;}<br/> &nbsp; &nbsp;}<br/>}<br/>function returnDate() //根据日期格式等返回用户选定的日期<br/>{<br/> &nbsp; &nbsp;if(WebCalendar.objExport)<br/> &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp;var returnValue;<br/> &nbsp; &nbsp; &nbsp; &nbsp;var a = (arguments.length==0) ? WebCalendar.day[this.id.substr(8)].split(&quot;/&quot;) : arguments[0].split(&quot;/&quot;);<br/> &nbsp; &nbsp; &nbsp; &nbsp;var d = WebCalendar.format.match(/^(&#92;w{4})(-&#124;&#92;/)(&#92;w{1,2})&#92;2(&#92;w{1,2})$/);<br/> &nbsp; &nbsp; &nbsp; &nbsp;if(d==null){alert(&quot;你设定的日期输出格式不对！&#92;r&#92;n&#92;r&#92;n请重新定义 WebCalendar.format ！&quot;); return false;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;var flag = d[3].length==2 &#124;&#124; d[4].length==2; //判断返回的日期格式是否要补零<br/> &nbsp; &nbsp; &nbsp; &nbsp;returnValue = flag ? a[2] +d[2]+ appendZero(a[1]) +d[2]+ appendZero(a[0]) : a[2] +d[2]+ a[1] +d[2]+ a[0];<br/> &nbsp; &nbsp; &nbsp; &nbsp;if(WebCalendar.timeShow)<br/> &nbsp; &nbsp; &nbsp; &nbsp;{<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var h = new Date().getHours(), m = new Date().getMinutes(), s = new Date().getSeconds();<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;returnValue += flag ? &quot; &quot;+ appendZero(h) +&quot;:&quot;+ appendZero(m) +&quot;:&quot;+ appendZero(s) : &quot; &quot;+ &nbsp;h &nbsp;+&quot;:&quot;+ m +&quot;:&quot;+ s;<br/> &nbsp; &nbsp; &nbsp; &nbsp;}<br/> &nbsp; &nbsp; &nbsp; &nbsp;WebCalendar.objExport.value = returnValue;<br/> &nbsp; &nbsp; &nbsp; &nbsp;hiddenCalendar();<br/> &nbsp; &nbsp;}<br/>}<br/>function document.onclick()<br/>{<br/> &nbsp; &nbsp;if(WebCalendar.eventSrc != window.event.srcElement) hiddenCalendar();<br/>}<br/><br/><br/><br/>Tags - <a href="http://www.dzhope.com/tags/js/" rel="tag">js</a>
]]>
</description>
</item><item>
<link>http://www.dzhope.com/post//#blogcomment</link>
<title><![CDATA[[评论] javascript常用备忘]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.dzhope.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>