<div id="test"></div> <script> function D(layid,date){ this.lay=layid; this.d=date?date:new Date(); } D.prototype.init=function(date){
var val=date?date:this.d.valueOf(); var d=new Date(val); var str=d.getHours()+':'+d.getMinutes()+':'+d.getSeconds(); document.getElementById(this.lay).innerHTML=str; var _this=this; val+=1000; setTimeout(function(){_this.init(val);},1000); } new D('test').init(); </script>
var str = ""; document.writeln(" <div id=\"_contents\" style=\"padding:6px; background-color:#E3E3E3; font-size: 12px; border: 1px solid #777777; position:absolute; left:?px; top:?px; width:?px; height:?px; z-index:1; visibility:hidden\">"); str += "\u65f6 <select name=\"_hour\">"; for (h = 0; h <= 9; h++) { str += " <option value=\"0" + h + "\">0" + h + " </option>"; } for (h = 10; h <= 23; h++) { str += " <option value=\"" + h + "\">" + h + " </option>"; } str += " </select> \u5206 <select name=\"_minute\">"; for (m = 0; m <= 9; m++) { str += " <option value=\"0" + m + "\">0" + m + " </option>"; } for (m = 10; m <= 59; m++) { str += " <option value=\"" + m + "\">" + m + " </option>"; } str += " </select> \u79d2 <select name=\"_second\">"; for (s = 0; s <= 9; s++) { str += " <option value=\"0" + s + "\">0" + s + " </option>"; } for (s = 10; s <= 59; s++) { str += " <option value=\"" + s + "\">" + s + " </option>"; } str += " </select> <input name=\"queding\" type=\"button\" onclick=\"_select()\" value=\"\u786e\u5b9a\" style=\"font-size:12px\" /> </div>"; document.writeln(str); var _fieldname; function _SetTime(tt) { _fieldname = tt; var ttop = tt.offsetTop; //TT控件的定位点高 var thei = tt.clientHeight; //TT控件本身的高 var tleft = tt.offsetLeft; //TT控件的定位点宽 while (tt = tt.offsetParent) { ttop += tt.offsetTop; tleft += tt.offsetLeft; } document.all._contents.style.top = ttop + thei + 4; document.all._contents.style.left = tleft; document.all._contents.style.visibility = "visible"; } function _select() { _fieldname.value = document.all._hour.value + ":" + document.all._minute.value + ":" + document.all._second.value; document.all._contents.style.visibility = "hidden"; } 开始时间:<input type="text" name="d" style="width:120px;" onclick="_SetTime(this)" readOnly="true">
<script type="text/javascript">
var date=new Date();setInterval(function(){
alert("现在的时间是:"+date.getHours()+"时"+date.getMinutes()+"分"+date.getSeconds()+"秒");},1000);</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
<script type="text/javascript">
/**
* @author develop_design_level
* date 2009-11-05
* @param {Object} id
*/
function $(id){
return document.getElementById(id);
}
function timeRun(){
var d = new Date();
$('hourId').innerHTML = d.getHours() + '点';
$('minId').innerHTML = d.getMinutes() + '分';
$('secId').innerHTML = d.getSeconds() + '秒';
}
window.onload = function(){
window.setInterval('timeRun()',1000);
};
</script>
</head>
<body>
<table width="200" border="1">
<tr>
<td id="hourId">
</td>
<td id="minId">
</td>
<td id="secId">
</td>
</tr>
</table>
</body>
</html>
=== 结贴,给分 ===
得到满意的答案,立即结贴给分,是一种良好的习惯和美德
<div id="test"></div>
<script>
function D(layid,date){
this.lay=layid;
this.d=date?date:new Date();
}
D.prototype.init=function(date){
var val=date?date:this.d.valueOf();
var d=new Date(val);
var str=d.getHours()+':'+d.getMinutes()+':'+d.getSeconds();
document.getElementById(this.lay).innerHTML=str;
var _this=this;
val+=1000;
setTimeout(function(){_this.init(val);},1000);
}
new D('test').init();
</script>
document.writeln(" <div id=\"_contents\" style=\"padding:6px; background-color:#E3E3E3; font-size: 12px; border: 1px solid #777777; position:absolute; left:?px; top:?px; width:?px; height:?px; z-index:1; visibility:hidden\">");
str += "\u65f6 <select name=\"_hour\">";
for (h = 0; h <= 9; h++) {
str += " <option value=\"0" + h + "\">0" + h + " </option>";
}
for (h = 10; h <= 23; h++) {
str += " <option value=\"" + h + "\">" + h + " </option>";
}
str += " </select> \u5206 <select name=\"_minute\">";
for (m = 0; m <= 9; m++) {
str += " <option value=\"0" + m + "\">0" + m + " </option>";
}
for (m = 10; m <= 59; m++) {
str += " <option value=\"" + m + "\">" + m + " </option>";
}
str += " </select> \u79d2 <select name=\"_second\">";
for (s = 0; s <= 9; s++) {
str += " <option value=\"0" + s + "\">0" + s + " </option>";
}
for (s = 10; s <= 59; s++) {
str += " <option value=\"" + s + "\">" + s + " </option>";
}
str += " </select> <input name=\"queding\" type=\"button\" onclick=\"_select()\" value=\"\u786e\u5b9a\" style=\"font-size:12px\" /> </div>";
document.writeln(str);
var _fieldname;
function _SetTime(tt) {
_fieldname = tt;
var ttop = tt.offsetTop; //TT控件的定位点高
var thei = tt.clientHeight; //TT控件本身的高
var tleft = tt.offsetLeft; //TT控件的定位点宽
while (tt = tt.offsetParent) {
ttop += tt.offsetTop;
tleft += tt.offsetLeft;
}
document.all._contents.style.top = ttop + thei + 4;
document.all._contents.style.left = tleft;
document.all._contents.style.visibility = "visible";
}
function _select() {
_fieldname.value = document.all._hour.value + ":" + document.all._minute.value + ":" + document.all._second.value;
document.all._contents.style.visibility = "hidden";
} 开始时间:<input type="text" name="d" style="width:120px;" onclick="_SetTime(this)" readOnly="true">