代码:--------------------------------------------------------------------------------
<style type="text/css">
body {
background-color: #d4d0c8;
}
.m_fieldset {
padding: 0,10,5,10;
text-align: center;
width: 150px;
}
.m_legend {
font-family: tahoma;
font-size: 11px;
padding-bottom: 5px;
}
.m_frameborder {
border-left: 2px inset #d4d0c8;
border-top: 2px inset #d4d0c8;
border-right: 2px inset #ffffff;
border-bottom: 2px inset #ffffff;
width: 100px;
height: 19px;
background-color: #ffffff;
overflow: hidden;
text-align: right;
font-family: "tahoma";
font-size: 10px;
}
.m_arrow {
width: 16px;
height: 8px;
font-family: "webdings";
font-size: 7px;
line-height: 2px;
padding-left: 2px;
cursor: default;
}
.m_input {
width: 18px;
height: 14px;
border: 0px solid black;
font-family: "tahoma";
font-size: 9px;
text-align: right;
ime-mode:disabled;
}
</style>
<script language="javascript">
//written by cloudchen, 2004/03/15
function minute(name,fname)
{
this.name = name;
this.fname = fname || "m_input";
this.timer = null;
this.fobj = null;
this.tostring = function()
{
var objdate = new date();
var sminute_common = "class=/"m_input/" maxlength=/"2/" name=/""+this.fname+"/" onfocus=/""+this.name+".setfocusobj(this)/" onblur=/""+this.name+".settime(this)/" onkeyup=/""+this.name+".prevent(this)/" onkeypress=/"if (!/[0-9]/.test(string.fromcharcode(event.keycode)))event.keycode=0/" onpaste=/"return false/" ondragenter=/"return false/"";
var sbutton_common = "class=/"m_arrow/" onfocus=/"this.blur()/" onmouseup=/""+this.name+".controltime()/" disabled"
var str = "";
str += "<table border=/"0/" cellspacing=/"0/" cellpadding=/"0/">"
str += "<tr>"
str += "<td>"
str += "<div class=/"m_frameborder/">"
str += "<input radix=/"24/" value=/""+this.formattime(objdate.gethours())+"/" "+sminute_common+">:"
str += "<input radix=/"60/" value=/""+this.formattime(objdate.getminutes())+"/" "+sminute_common+">:"
str += "<input radix=/"60/" value=/""+this.formattime(objdate.getseconds())+"/" "+sminute_common+">"
str += "</div>"
str += "</td>"
str += "<td>"
str += "<table border=/"0/" cellspacing=/"2/" cellpadding=/"0/">"
str += "<tr><td><button id=/""+this.fname+"_up/" "+sbutton_common+">5</button></td></tr>"
str += "<tr><td><button id=/""+this.fname+"_down/" "+sbutton_common+">6</button></td></tr>"
str += "</table>"
str += "</td>"
str += "</tr>"
str += "</table>"
return str;
}
this.play = function()
{
this.timer = setinterval(this.name+".playback()",1000);
}
this.formattime = function(stime)
{
stime = ("0"+stime);
return stime.substr(stime.length-2);
}
this.playback = function()
{
var objdate = new date();
var arrdate = [objdate.gethours(),objdate.getminutes(),objdate.getseconds()];
var objminute = document.getelementsbyname(this.fname);
for (var i=0;i<objminute.length;i++)
{
objminute[i].value = this.formattime(arrdate[i])
}
}
this.prevent = function(obj)
{
clearinterval(this.timer);
this.setfocusobj(obj);
var value = parseint(obj.value,10);
var radix = parseint(obj.radix,10)-1;
if (obj.value>radix||obj.value<0)
{
obj.value = obj.value.substr(0,1);
}
}
this.controltime = function(cmd)
{
event.cancelbubble = true;
if (!this.fobj) return;
clearinterval(this.timer);
var cmd = event.srcelement.innertext=="5"?true:false;
var i = parseint(this.fobj.value,10);
var radix = parseint(this.fobj.radix,10)-1;
if (i==radix&&cmd)
{
i = 0;
}
else if (i==0&&!cmd)
{
i = radix;
}
else
{
cmd?i++:i--;
}
this.fobj.value = this.formattime(i);
this.fobj.select();
}
this.settime = function(obj)
{
obj.value = this.formattime(obj.value);
}
this.setfocusobj = function(obj)
{
eval(this.fname+"_up").disabled = eval(this.fname+"_down").disabled = false;
this.fobj = obj;
}
this.gettime = function()
{
var arrtime = new array(2);
for (var i=0;i<document.getelementsbyname(this.fname).length;i++)
{
arrtime[i] = document.getelementsbyname(this.fname)[i].value;
}
return arrtime.join(":");
}
}
</script>
<style type="text/css">
body {
background-color: #d4d0c8;
}
.c_fieldset {
padding: 0,10,5,10;
text-align: center;
width: 180px;
}
.c_legend {
font-family: tahoma;
font-size: 11px;
padding-bottom: 5px;
}
.c_frameborder {
border-left: 2px inset #d4d0c8;
border-top: 2px inset #d4d0c8;
border-right: 2px inset #ffffff;
border-bottom: 2px inset #ffffff;
background-color: #ffffff;
overflow: hidden;
font-family: "tahoma";
font-size: 10px;
width:160px;
height:120px;
}
.c_frameborder td {
width: 23px;
height: 16px;
font-family: "tahoma";
font-size: 11px;
text-align: center;
cursor: default;
}
.c_frameborder .selected {
background-color:#0a246a;
width:12px;
height:12px;
color:white;
}
.c_frameborder span {
width:12px;
height:12px;
}
.c_arrow {
width: 16px;
height: 8px;
font-family: "webdings";
font-size: 7px;
line-height: 2px;
padding-left: 2px;
cursor: default;
}
.c_year {
font-family: "tahoma";
font-size: 11px;
cursor: default;
width:55px;
height:19px;
}
.c_month {
width:75px;
height:20px;
font:11px "tahoma";
}
.c_datehead {
background-color:#808080;
color:#d4d0c8;
}
</style>
<script language="javascript">
//written by cloudchen, 2004/03/16
function calendar(name,fname)
{
this.name = name;
this.fname = fname || "calendar";
this.year = new date().getfullyear();
this.month = new date().getmonth();
this.date = new date().getdate();
//private
this.tostring = function()
{
var str = "";
str += "<table border=/"0/" cellspacing=/"3/" cellpadding=/"0/" onselectstart=/"return false/">";
str += "<tr>";
str += "<td>";
str += this.drawmonth();
str += "</td>";
str += "<td align=/"right/">";
str += this.drawyear();
str += "</td>";
str += "</tr>";
str += "<tr>";
str += "<td colspan=/"2/">";
str += "<div class=/"c_frameborder/">";
str += "<table border=/"0/" cellspacing=/"0/" cellpadding=/"0/" class=/"c_datehead/">";
str += "<tr>";
str += "<td>日</td><td>一</td><td>二</td><td>三</td><td>四</td><td>五</td><td>六</td>";
str += "</tr>";
str += "</table>";
str += this.drawdate();
str += "</div>";
str += "</td>";
str += "</tr>";
str += "</table>";
return str;
}
//private
this.drawyear = function()
{
var str = "";
str += "<table border=/"0/" cellspacing=/"0/" cellpadding=/"0/">";
str += "<tr>";
str += "<td>";
str += "<input class=/"c_year/" maxlength=/"4/" value=/""+this.year+"/" name=/""+this.fname+"/" id=/""+this.fname+"_year/" readonly>";
//datefield
str += "<input type=/"hidden/" name=/""+this.fname+"/" value=/""+this.date+"/" id=/""+this.fname+"_date/">";
str += "</td>";
str += "<td>";
str += "<table cellspacing=/"2/" cellpadding=/"0/" border=/"0/">";
str += "<tr>";
str += "<td><button class=/"c_arrow/" onfocus=/"this.blur()/" onclick=/"event.cancelbubble=true;document.getelementbyid('"+this.fname+"_year').value++;"+this.name+".redrawdate()/">5</button></td>";
str += "</tr>";
str += "<tr>";
str += "<td><button class=/"c_arrow/" onfocus=/"this.blur()/" onclick=/"event.cancelbubble=true;document.getelementbyid('"+this.fname+"_year').value--;"+this.name+".redrawdate()/">6</button></td>";
str += "</tr>";
str += "</table>";
str += "</td>";
str += "</tr>";
str += "</table>";
return str;
}
//priavate
this.drawmonth = function()
{
var amonthname = ["一","二","三","四","五","六","七","八","九","十","十一","十二"];
var str = "";
str += "<select class=/"c_month/" name=/""+this.fname+"/" id=/""+this.fname+"_month/" onchange=/""+this.name+".redrawdate()/">";
for (var i=0;i<amonthname.length;i++) {
str += "<option value=/""+(i+1)+"/" "+(i==this.month?"selected":"")+">"+amonthname[i]+"月</option>";
}
str += "</select>";
return str;
}
//private
this.drawdate = function()
{
var str = "";
var fday = new date(this.year,this.month,1).getday();
var fdate = 1-fday;
var lday = new date(this.year,this.month+1,0).getday();
var ldate = new date(this.year,this.month+1,0).getdate();
str += "<table border=/"0/" cellspacing=/"0/" cellpadding=/"0/" id=/""+this.fname+"_datetable"+"/">";
for (var i=1,j=fdate;i<7;i++)
{
str += "<tr>";
for (var k=0;k<7;k++)
{
str += "<td><span"+(j==this.date?" class=/"selected/"":"")+" onclick=/""+this.name+".redrawdate(this.innertext)/">"+(isdate(j++))+"</span></td>";
}
str += "</tr>";
}
str += "</table>";
return str;
function isdate(n)
{
return (n>=1&&n<=ldate)?n:"";
}
}
//public
this.redrawdate = function(d)
{
this.year = document.getelementbyid(this.fname+"_year").value;
this.month = document.getelementbyid(this.fname+"_month").value-1;
this.date = d || this.date;
document.getelementbyid(this.fname+"_year").value = this.year;
document.getelementbyid(this.fname+"_month").selectedindex = this.month;
document.getelementbyid(this.fname+"_date").value = this.date;
if (this.date>new date(this.year,this.month+1,0).getdate()) this.date = new date(this.year,this.month+1,0).getdate();
document.getelementbyid(this.fname+"_datetable").outerhtml = this.drawdate();
}
//public
this.getdate = function(delimiter)
{
if (!delimiter) delimiter = "/";
var avalue = [this.year,(this.month+1),this.date];
return avalue.join(delimiter);
}
}
</script>
<table border="0">
<tr><td>
<fieldset class="c_fieldset"><legend class="c_legend">日期(t)</legend>
<!-- 调用日历 -->
<script>
var c = new calendar("c");
document.write(c);
</script>
<!-- 调用日历 -->
</fieldset>
</td>
<td valign="top">
<fieldset class="m_fieldset"><legend class="m_legend">时间(t)</legend>
<!-- 调用时间钟 -->
<script>
var m = new minute("m");
m.play();
document.write(m);
</script>
<!-- 调用时间钟 -->
</fieldset>
</td></tr>
<tr>
<td colspan="2">
<button onclick="alert(c.getdate())" style="font:8px webdings;width:15px;height:15px;line-height:6px;">4</button>
<button style="font:10px arial;height:15px;height:16px;border:0px;" onfocus="this.blur()">getdate</button>
<button onclick="alert(m.gettime())" style="font:8px webdings;width:15px;height:15px;line-height:6px;">4</button>
<button style="font:10px arial;height:15px;height:16px;border:0px;" onfocus="this.blur()">gettime</button>
</td>
</tr>
</table>