<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>抽奖</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript">
var flag = false;
var flag1 = false;
window.onload = function(){
random();
}
function random(){
document.getElementById("span1").innerHTML = Math.random(); //该方法产生一个0到1之间的浮点数。
document.getElementById("span2").innerHTML = Math.floor(Math.random()*10+1); //1-10
document.getElementById("span3").innerHTML = Math.floor(Math.random()*100);//0-99
var arr = ["太阳光大、父母恩大、君子量大、小人气大","成功是优点的发挥,失败是缺点的累积","不要小看自己,因为人有无限的可能",
"口说好话、心想好意、身行好事","原谅别人就是善待自己","手心向下是助人,手心向上是求人;助人快乐,求人痛苦"];
var index = Math.floor((Math.random()*arr.length));
document.getElementById("span4").innerHTML = arr[index];
if(!flag){
setTimeout(random,100);
}
}
function stup(){
if(!flag1){
flag = true;
flag1 = true;
document.getElementById("stup").value = " 开始 ";
}else{
flag = false;
flag1 = false;
document.getElementById("stup").value = " 停止 ";
random();
}
}
</script>
</head>
<body>
0到1之间的浮点数: <span id = span1></span> <br />
1到10之间的正整数:<span id = span2></span><br />
0到99之间的正整数:<span id = span3></span><br />
<span id = span4></span><br />
<input id = "stup" type = "button" οnclick="stup()" value = " 停止 ">
</body>
</html>