日期:2014-05-16  浏览次数:20281 次

请高手看看下面的脚本代码错在哪儿?
页面是ASP.net,在页面中有一个服务器控件,用来显示服务器上的当前时间,下面的脚本是在客户端显示服务器时间的代码,但总是报告第一行“var   strTime:   String;”缺少 "; ",如果把第一行去掉,则又报告“hh=int(strTime.substr(0,2));”缺少对象。请高手看看,我的脚本代码错在哪?
<script   language= "javascript ">
displaytime();

function   displaytime()
{
    var   strTime:   String;
    strTime   =   document.getElementById( " <%=txtCurTime.ClientID   %> ").innerText;
    hh   =   int(strTime.substr(0,2));
    mm   =   int(strTime.substr(3,2));
    ss   =   int(strTime.substr(6,2));
    if(ss> =59)
    {
        ss   =   0;
        mm   ++;
    }
    else
    {
        ss   ++;
    }
    if(mm> =59)
    {
        mm   =   0;
        hh   ++;
    }
    else
    {
        mm   ++;
    }
    document.getElementByID( " <%=txtCurTime.ClientID   %> ").innerText   =   FormatTime(hh,   mm,   ss);
    setTimeout(displaytime(),   1000);
}

function   FormatTime(hh:int,   mm:int,   ss:int):   String
{
    var   strRet:   String;
    strRet   =   " ";
    if(hh   >   9)
    {
        strRet   +=   "0 ";
    }
    strRet   +=   hh.tostring()   +   ": ";
    if(mm   >   9)
    {
        strRet   +=   "0 ";
    }
    strRet   +=   mm.tostring()   +   ": ";
    if(ss   >   9)
    {
        strRet   +=   "0 ";
    }
    strRet   +=   ss.tostring();
    return   strRet;
}
</javascript>


------解决方案--------------------
var strTime: String;??直接
var strTime;就可以了吧?
你试一下
------解决方案--------------------
int 是个什么东西

定义了吗?

------解决方案--------------------
看不懂LZ的JS语法,更看不懂LZ的代码逻辑。大概理解了你的功能,下面代码可以实现:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN ">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<meta http-equiv=Content-Type content= "text/html;charset=utf-8 ">
<META NAME= "Generator " CONTENT= "EditPlus ">
<META NAME= "Author " CONTENT= "Philoo ">
<META NAME= "Keywords " CONTENT= " ">
<META NAME= "Description " CONTENT= " ">
<SCRIPT LANGUAGE= "JavaScript ">
<!--
setInterval( 'displaytime() ', 1000);

function displaytime()
{
var strTime = document.getElementById( "txt1 ").value;//