关于JS与JSP的传值问题
<%@ page language="java" contentType="text/html; charset=GB2312"
pageEncoding="GB2312"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312">
<script language="JavaScript">
<!-- //
var startTime = new Date();//这里的new Date()换成你后台传递的时间
var EndTime=startTime.getTime()+60*1000;//这个设置倒计时的时间,按毫秒算,也即60*1000就是一分钟
function GetRTime(){
var NowTime = new Date();
var nMS =EndTime - NowTime.getTime();
var nS=Math.floor(nMS/1000) % 60;
document.getElementById("RemainS").innerHTML=nS;
ns=
setTimeout("GetRTime()",1000);
}
window.onload=GetRTime;
// -->
</script>
<title>Insert title here</title>
</head>
<body>
<div id="CountMsg">倒计时还有:<strong id="RemainS">XX</strong>秒</div>
我想在这里加判断语句
假如时间到了0秒。打印出“OK”!
</body>
</html>
怎么把JS的值传到jsp中啊。。而且要打印出“ok”!
[解决办法]
<HTML> <HEAD> <TITLE> New Document </TITLE> </HEAD> <BODY> <html:form action= "/XXXAction "> <table width= "100% " height= "230 " border= "0 " cellpadding= "0 " cellspacing= "0 "> <tr> <td> name: <html:text property= "name "/> </td> </tr> <tr> <td> <input type= "set " value= "set " onclick= "set(); "> </td> </tr> </table> </BODY> </html:form> <script language= "javascript "> function set(){ document.XXXForm.name.value= "ok "; return true; } </script> </HTML>
[解决办法]
设置全局变量啊
var nS;
function GetRTime(){
var NowTime = new Date();
var nMS =EndTime - NowTime.getTime();
nS=Math.floor(nMS/1000) % 60;
if(nS == 0){
alert("OK")}
document.getElementById("RemainS").innerHTML=nS;
ns=
setTimeout("GetRTime()",1000);
}