一个简单的JSP+JS定时刷新实例

    技术2022-05-20  36

    JSP

    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="java.text.MessageFormat" %> <html> <head> <title>Refresh Test</title> <SCRIPT LANGUAGE="JavaScript" src="refresh.js" mce_src="refresh.js"></SCRIPT> </head> <body οnlοad="timer15()"> <% String theTime=MessageFormat.format("{0,date,HH:mm:ss}" , new Object[] { new java.util.Date(System.currentTimeMillis()) }); %> Time=<%=theTime%> </body> </html>

     

     

     

    JS的SetTimeout方法,单位是毫秒

    function fresh() { window.location.reload(); } function timer15() { setTimeout("fresh()",15000); } function timer60() { setTimeout("fresh()",60000); } function timer120() { setTimeout("fresh()",120000); } function timer180() { setTimeout("fresh()",180000); } function timer300() { setTimeout("fresh()",300000); } function timer600() { setTimeout("fresh()",600000); }

     

     

     

    使用HTML中的<meta>标签刷新,单位是秒

    <meta http-equiv="refresh" content="5" /> <meta http-equiv="refresh" content="5;url=http://community.csdn.net/" />


    最新回复(0)