我做了一个按钮,按下它会带来服务器时间,所以有这个 html 和 js 文件,我希望它从 time.tcl 文件中获取时间,请帮助我:
1.我的文件使用 html 和 Javascript :
<html>
<body>
<input value="Get Time" type="button" onclick='JavaScript:showCurrentTime()' name="GetTime">
<div id="result" align="center"></div>
<script language="Javascript">
function showCurrentTime()
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject(“Microsoft.XMLHTTP”);
}
var xmlhttp;
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5
xmlhttp=new ActiveXObject(“Microsoft.XMLHTTP”);}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("result").innerHTML=xmlhttp.responseText;
}
xmlhttp.open(“GET”,”time.tcl”,true);
</script>
</body>
</html>
2.我的 time.tcl 文件:
set now [clock seconds]
# print default-formatted time
puts [clock format $now]
# print custom formatted time
set fmt "Today is day %j of the current year."
puts [clock format $now -format $fmt]
set today [clock seconds]
set fmt "%Y-%m-%d"
puts "The current date is [clock format $today -format $fmt]."