今天練習Javascript,寫了幾個函數,保存下來,以備後用
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="jsTest.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
<head>
</head>
<script language="javascript">
function win() //動態生成子窗口
{
var strHTML = "<p style='color:red'>測試測試測試</p> "
strHTML += "<input><a href='#' οnclick='self.close()'>關閉</a>"
strHTML += "<input type=button value='關閉' οnclick='self.close()'>"
var a=window.open()
a.document.open()
a.document.write(strHTML)
a.document.close()
}
function showtime() //顯示時間函數
{
mytime=new Date();
mytime=mytime.getHours()+":"+mytime.getMinutes()
+":"+mytime.getSeconds();
document.myform.mytext.value=mytime;
window.clearTimeout(mytimeout);
var mytimeout=window.setTimeout("showtime()",1000)
}
function nowTime() //顯示時間函數
{
var nowData = new Date()
var year = nowData.getYear()
var month = nowData.getMonth()
var day = nowData.getDate()
var hour = nowData.getHours()
var minute = nowData.getMinutes()
var second = nowData.getSeconds()
document.myform.mytest.value = year+"年"+(month+1)+"月"+day+"日"+hour+"點"+minute+"分"+second+"秒"
window.setTimeout("nowTime()",1000)
}
</script>
<body bgcolor="#FFFFFF" text="#000000">
<form name="myform">
<table border="0" align="center">
<tr>
<td><input type="text" name="mytext" size="20" style="background-color:lightgreen;color:blue"></td>
<td><input type="text" name="mytest" size="20" style="background-color:lightgreen;color:blue"></td>
<td><input type="button" value='打開子窗口' οnclick="win()"></td>
<td><input type="button" value="設置時間" οnclick='window.setTimeout("showtime()",1000)' style="background-color:lightblue;"></td>
<td><input type="button" value="當前時間" οnclick='window.setTimeout("nowTime()",1000)' style="background-color:lightblue;"></td>
</tr>
</table>
</form>
</body>
</html>