1.在HTML文件中如何调用JavaScript?10’
<script language="JavaScript" type="text/javascript" src="filename.js">
</script>
2.用户点击鼠标执行的脚本是什么方面的例子?10’
事件处理程序。
3.JavaScript程序中变量的用途是什么? 5’
○用来存储数字,字符串。
●用来存储数字,日期或其他值。
15’
得分:50’
满分:100’
疑问:如何使时间自动刷新?
<script language="JavaScript" type="text/javascript" src="filename.js">
</script>
2.用户点击鼠标执行的脚本是什么方面的例子?10’
事件处理程序。
3.JavaScript程序中变量的用途是什么? 5’
○用来存储数字,字符串。
●用来存储数字,日期或其他值。
15’
<h1>Date and Time</h1>
<script language="javascript">
now=new Date();
locatime=now.toString();
utctime=now.toGMTString();
document.write("<b>loca time:</b>"+locatime+"<br>");
document.write("<b>UTC time:</b>"+utctime);
/*hours=getHours();
mins=getMinutes();
secs=getSeconds();*/
hours=now.getHours();
mins=now.getMinutes();
secs=now.getSeconds()
document.write("<h1>"+hours+":"+mins+":"+secs+"</h1>");
</script>
<script language="javascript">
now=new Date();
locatime=now.toString();
utctime=now.toGMTString();
document.write("<b>loca time:</b>"+locatime+"<br>");
document.write("<b>UTC time:</b>"+utctime);
/*hours=getHours();
mins=getMinutes();
secs=getSeconds();*/
hours=now.getHours();
mins=now.getMinutes();
secs=now.getSeconds()
document.write("<h1>"+hours+":"+mins+":"+secs+"</h1>");
</script>
得分:50’
满分:100’
疑问:如何使时间自动刷新?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>The Time</title>
<script>
//定义时钟显示的函数
function displayTime() {
var today = new Date();
// 定义日期对象
var hours = today.getHours();
var minutes = today.getMinutes();
var seconds = today.getSeconds();
// 从日期对象中中获得时间信息
minutes = fixTime(minutes);
seconds = fixTime(seconds);
// 引入fixTime()函数,使分和秒可以正常显示,对于小于10的数字则在该数字前加一个0
var the_time = hours + ":" + minutes + ":" + seconds;
//将时间字符串组合在一起并写出
window.document.the_form.the_text.value = the_time;
//把表格的值重新写一遍,相当于刷新时间
the_timeout= setTimeout('displayTime();',500);
//每半秒钟执行一次该函数,即500毫秒
}
function fixTime(the_time)
{if (the_time <10) { the_time = "0" + the_time; } return the_time; }
</script>
</head>
<body onload=displayTime()>
<form name="the_form">
<p><font face="宋体"><input type="text" name="the_text" size="16"> </form>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>The Time</title>
<script>
//定义时钟显示的函数
function displayTime() {
var today = new Date();
// 定义日期对象
var hours = today.getHours();
var minutes = today.getMinutes();
var seconds = today.getSeconds();
// 从日期对象中中获得时间信息
minutes = fixTime(minutes);
seconds = fixTime(seconds);
// 引入fixTime()函数,使分和秒可以正常显示,对于小于10的数字则在该数字前加一个0
var the_time = hours + ":" + minutes + ":" + seconds;
//将时间字符串组合在一起并写出
window.document.the_form.the_text.value = the_time;
//把表格的值重新写一遍,相当于刷新时间
the_timeout= setTimeout('displayTime();',500);
//每半秒钟执行一次该函数,即500毫秒
}
function fixTime(the_time)
{if (the_time <10) { the_time = "0" + the_time; } return the_time; }
</script>
</head>
<body onload=displayTime()>
<form name="the_form">
<p><font face="宋体"><input type="text" name="the_text" size="16"> </form>
</body>
</html>