js鼠标点名器
相关说明:js是指javaScript
<html>
<head>
<meta charset="UTF-8">
<title>点名器 </title>
<style>
#show {
margin: auto;
margin-top: 200px;
font-size: 100px; /*字体大小*/
width: 500px; /*宽度*/
height: 140px; /*高度*/
background: orangered; /*背景颜色*/
color: #FFFFFF; /*字体颜色*/
border-radius: 15px; /*边框倒角*/
text-align: center;
cursor: pointer;
}
</style>
</head>
<body>
<div id="show" onclick="start()">别紧张</div>
</body>
<script>
var names = "张三,李四,王五,赵六,,李聪,王虎";
var arr = names.split(",");
//定义定时器记录值
var time;
//定义方法
function start() {
if(time){
clearInterval(time);
time=null;
}else {
time=setInterval("run()",100);
}
}
//定义run()方法
function run() {
//通过随机数产生索引
var num = Math.ceil(Math.random()*(arr.length-1));
document.getElementById("show").innerHTML=arr[num];
}
window.onkeydown = function () {
if(event.keyCode ==13){
start();
}
if (event.keyCode == 123){
return false;
}
}
window.oncontextmenu = function () {
alert("不允许操作");
return false;
}
</script>
</html>
|