把取消显示时间按钮写成下边这样:
<input type=button value="取消时间显示" onclick="document.myform.mytext.value=''" >
就是加上个单击事件!

解决方案 »

  1.   

    <html>
    <head>
    <title>window.setTimeout()函数</title>
    <script laguage="javascript">
    <!--
    var mytimeout
    function showtime()
    {
    mytime=new Date();
    mytime=mytime.getHours()+":"+mytime.getMinutes()+":"+mytime.getSeconds();
    document.myform.mytext.value=mytime;
    window.clearTimeout(mytimeout);
    mytimeout=window.setTimeout("showtime()",1000);
    }
    //-->
    </script>
    </head>
    <body >
    <form name="myform">
    <table border=0 align=center>
    <tr>
    <td><input type=text name=mytext size=20 ></td>
    <td><input type=button value="设置时间" onclick="showtime();" ></td>
    <td><input type=button value="取消时间显示" onclick="window.clearTimeout(mytimeout);document.myform.mytext.value=''" ></td>
    </tr>
    </table>
    </form>
    </body>
    </html>