我创建了一个js文件,如何在default.aspx的“源”页面中的两个地方分别引用它们?function showtime() //时间
{
var now_time = new Date(); //创建时间对象的实例
var hours = now_time.getHours(); //获得当前小时数
var minutes = now_time.getMinutes(); //获得当前分钟数
var seconds = now_time.getSeconds(); //获得当前秒数
var timer = "" + ((hours > 12) ? hours - 12 : hours); //将小时数值赋予变量timer
timer += ((minutes < 10) ? ":0" : ":") + minutes; //将分钟数值赋予变量timer
timer += ((seconds < 10) ? ":0" : ":") + seconds; //将秒数值赋予变量timer
timer +=" " + ((hours > 12) ? "pm" : "am"); //将字符am或pm赋予变量timer
document.clock.show.value = timer; //在名为clock的表单中输出变量timer的值
setTimeout("showtime()",1000); //设置每隔一秒钟自动调用一次showtime()函数}
function showdate() //日期
{
var now_date = new Date();
var years = now_date.getYear();
var months = now_date.getMonth();
var dates = now_date.getDate();
var days = now_date.getDay();
if(now_date.getDay()==0) days = "星期日"
if(now_date.getDay()==1) days = "星期一"
if(now_date.getDay()==2) days = "星期二"
if(now_date.getDay()==3) days = "星期三"
if(now_date.getDay()==4) days = "星期四"
if(now_date.getDay()==5) days = "星期五"
if(now_date.getDay()==6) days = "星期六"
var today = " 今天是 " + years + "年" + (months+1) + "月" + dates + "日" + " "+days +" ";
document.clock.show.value = today;
}
{
var now_time = new Date(); //创建时间对象的实例
var hours = now_time.getHours(); //获得当前小时数
var minutes = now_time.getMinutes(); //获得当前分钟数
var seconds = now_time.getSeconds(); //获得当前秒数
var timer = "" + ((hours > 12) ? hours - 12 : hours); //将小时数值赋予变量timer
timer += ((minutes < 10) ? ":0" : ":") + minutes; //将分钟数值赋予变量timer
timer += ((seconds < 10) ? ":0" : ":") + seconds; //将秒数值赋予变量timer
timer +=" " + ((hours > 12) ? "pm" : "am"); //将字符am或pm赋予变量timer
document.clock.show.value = timer; //在名为clock的表单中输出变量timer的值
setTimeout("showtime()",1000); //设置每隔一秒钟自动调用一次showtime()函数}
function showdate() //日期
{
var now_date = new Date();
var years = now_date.getYear();
var months = now_date.getMonth();
var dates = now_date.getDate();
var days = now_date.getDay();
if(now_date.getDay()==0) days = "星期日"
if(now_date.getDay()==1) days = "星期一"
if(now_date.getDay()==2) days = "星期二"
if(now_date.getDay()==3) days = "星期三"
if(now_date.getDay()==4) days = "星期四"
if(now_date.getDay()==5) days = "星期五"
if(now_date.getDay()==6) days = "星期六"
var today = " 今天是 " + years + "年" + (months+1) + "月" + dates + "日" + " "+days +" ";
document.clock.show.value = today;
}
下面直接用
<script type="text/javascript" src='youjsfile.js'></script>2.在代码中调用
<a href='javascript:showtime();'>查看时间</a>
<a href='javascript:showdate();'>查看日期</a>
<script type="text/javascript" src="含路径的js文件"></script>2. 在需要显示的地方调用,例如:当前是: <script type="text/javascript">showdate();showtime();</script>