如果你想分析一段VBScript和HTML混合的代码,特别地希望能够得到一段Javascript中调用函数的执行时间。正常来说,单纯通过下面的代码(Javascript自带的时间获取方法)得到的时间是不正确的,因为它是页面加载后的时间,而不是程序执行到这里的时间。
<
SCRIPT language
=
JavaScript
>
var day = "" ;
var month = "" ;
var ampm = "" ;
var ampmhour = "" ;
var myweekday = "" ;
var year = "" ;
mydate = new Date();
myweekday = mydate.getDay();
mymonth = mydate.getMonth() + 1 ;
myday = mydate.getDate();
myyear = mydate.getYear();
year = (myyear > 200 ) ? myyear : 1900 + myyear;
if (myweekday == 0 )
weekday = " 星期日 " ;
else if (myweekday == 1 )
weekday = " 星期一 " ;
else if (myweekday == 2 )
weekday = " 星期二 " ;
else if (myweekday == 3 )
weekday = " 星期三 " ;
else if (myweekday == 4 )
weekday = " 星期四 " ;
else if (myweekday == 5 )
weekday = " 星期五 " ;
else if (myweekday == 6 )
weekday = " 星期六 " ;
document.write( " <font color=#ff0000>北京时间 " + year + " 年 " + mymonth + " 月 " + myday + " 日 " + weekday + " </font> " );
</ SCRIPT >
var day = "" ;
var month = "" ;
var ampm = "" ;
var ampmhour = "" ;
var myweekday = "" ;
var year = "" ;
mydate = new Date();
myweekday = mydate.getDay();
mymonth = mydate.getMonth() + 1 ;
myday = mydate.getDate();
myyear = mydate.getYear();
year = (myyear > 200 ) ? myyear : 1900 + myyear;
if (myweekday == 0 )
weekday = " 星期日 " ;
else if (myweekday == 1 )
weekday = " 星期一 " ;
else if (myweekday == 2 )
weekday = " 星期二 " ;
else if (myweekday == 3 )
weekday = " 星期三 " ;
else if (myweekday == 4 )
weekday = " 星期四 " ;
else if (myweekday == 5 )
weekday = " 星期五 " ;
else if (myweekday == 6 )
weekday = " 星期六 " ;
document.write( " <font color=#ff0000>北京时间 " + year + " 年 " + mymonth + " 月 " + myday + " 日 " + weekday + " </font> " );
</ SCRIPT >
下面的代码中演示了如何获取代码中调用sample code的执行时间。页面调用以后(页面中会有错误)察看源代码,你会找到标有Before sample code:和After sample code:这两段字符串,这两个字符串后面紧跟的时间就是sample code执行的时间。
<%
...
@ LANGUAGE="VBSCRIPT"
%>
< html >
< head >
< title ></ title >
< meta name ="keywords" content ="" >
< meta name ="description" content ="" >
< meta name ="author" content ="" >
< meta http-equiv ="cache-control" content ="no-cache" >
< meta http-equiv ="content-type" content ="text/html; charset=shift_jis" >
< link rel ="STYLESHEET" type ="text/css" href ="./global_ns.css" >
< Script Language ="JavaScript" > ...
<%
'****************************
Response.Write("Before sample code: " & Now())
'****************************
%>
<% sample code %>
<%
'****************************
Response.Write("After sample code: " & Now())
'****************************
%>
</ script >
</ head >
< FORM ACTION ="./result.asp" METHOD ="GET" NAME ="PartsDB" target ="RESULT" onkeypress ="return EnterPress(event);" onClick ="highlight(event);" >
< table width ="800" CELLPADDING =0 CELLSPACING =0 BORDER =0 >
< tr >
< td > HTML
</ td >
</ tr >
</ TABLE >
</ FORM >
</ html >
< html >
< head >
< title ></ title >
< meta name ="keywords" content ="" >
< meta name ="description" content ="" >
< meta name ="author" content ="" >
< meta http-equiv ="cache-control" content ="no-cache" >
< meta http-equiv ="content-type" content ="text/html; charset=shift_jis" >
< link rel ="STYLESHEET" type ="text/css" href ="./global_ns.css" >
< Script Language ="JavaScript" > ...
<%
'****************************
Response.Write("Before sample code: " & Now())
'****************************
%>
<% sample code %>
<%
'****************************
Response.Write("After sample code: " & Now())
'****************************
%>
</ script >
</ head >
< FORM ACTION ="./result.asp" METHOD ="GET" NAME ="PartsDB" target ="RESULT" onkeypress ="return EnterPress(event);" onClick ="highlight(event);" >
< table width ="800" CELLPADDING =0 CELLSPACING =0 BORDER =0 >
< tr >
< td > HTML
</ td >
</ tr >
</ TABLE >
</ FORM >
</ html >
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1522836