• 在JSP页面中显示动态时间


    源地址:http://blog.csdn.net/aitcax/article/details/41285305

    静态时间:

    1.页面首部添加 <%@page import="java.util.Date"%>

    2.页面body中需要显示时间的地方使用 <%= new Date().toString() %> 即可。

    -------另:页面添加刷新按钮------

    <input type="button" onclick="javascript:window.location.reload()" value="刷新"/>

    另一种简单粗暴的方法:

    在需要显示时间的地方写上 <%=(new java.util.Date()).toLocaleString()%> 就可以了。

    动态时间:

    使用javascript。

    [javascript] 
    1. <script language=JavaScript>  
    2.     var timerID = null;  
    3.     var timerRunning = false;  
    4.     function stopclock() {  
    5.         if (timerRunning)  
    6.             clearTimeout(timerID);  
    7.         timerRunning = false;  
    8.     }  
    9.     function startclock() {  
    10.         stopclock();  
    11.         showtime();  
    12.     }  
    13.   
    14.     function showtime() {  
    15.         var now = new Date();  
    16.   
    17.         document.clock.thetime.value = now.toString();  
    18.         timerID = setTimeout("showtime()", 1000);  
    19.         timerRunning = true;  
    20.     }  
    21. </script>  

    在body中使用下面的代码显示时间。

    [html] 
    1. <body onload="startclock()">  
    2.  <form name=clock >  
    3. <input name=thetime style="font-size: 9pt;color:#000000;border:0" size=100>  
    4. </form>  
    5. </body>  


    注:其中javascript代码中startclock()和stopclock()两个函数可以不要,在onload处改成

    [html]
    1. onload="showtime()"  

    就可以了。

  • 相关阅读:
    后端程序员写的前端js代码模板
    setTimeOut传參数
    IP地址的分类——a,b,c 类是怎样划分的
    适配高分辨率的图片High DPI Images for Variable Pixel Densities
    atitit.提升软件开发效率大的总结O5
    Android Binder总结
    Enable Notepad++ 666 support both SCLEX_FORTRAN and SCLEX_F77
    client怎样调用IBinder接口对象
    文件系统损耗平衡算法
    u-boot支持yaffs映像烧写的补丁
  • 原文地址:https://www.cnblogs.com/aabbcc/p/5130255.html
Copyright © 2020-2023  润新知