JS 同一标签随机不停切换数据点菜--解决选择困难症
可视化的
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>
body{
background-color: aliceblue;
}
.box{
width: 1000px;
height: 240px;
/*background-color: aqua;*/
margin: auto;
margin-top: 100px;
clear: both;
}
#btn{
width: 100px;
height: 30px;
margin-left: 600px;
margin-top: 50px;
}
.name{
width: 100px;
height: 30px;
float: left;
background-color: antiquewhite;
margin-left: 10px;
margin-top: 10px;
text-align: center;
line-height: 30px;
}
#span{
float: right;
position: relative;
top: 55px;
right: 185px;
}
h1{
text-align: center;
}
</style>
</head>
<body>
<h1>随机点菜小玩意</h1>
<span id="span"></span>
<div class="box" id="box"></div>
<input type="button" id="btn" value="点名"/>
<script>
// 获取id函数
function my$(id){
return document.getElementById(id)
};
// 模拟后台数据
var arr = ["面条", "麻辣烫", "小碗菜", "盖饭"
];
// 动态创建层
for(var i =;i<arr.length;i++){
var div = document.createElement("div");
div.innerText=arr[i];
div.className="name";
my$("box").appendChild(div);
};
// 点菜
my$("btn").onclick=function(){
var peoples= arr.length;
// 监视按钮的状态
if(this.value==="点名"){
// 定时针
timeId=setInterval(function () {
// 清空所有层的颜色
for(var i =;i<arr.length;i++){
my$("box").children[i].style.background=""
};
// 留下当前层的颜色
var random = parseInt(Math.random()*peoples);
my$("box").children[random].style.background="red";
},);
this.value="停止";
}else{
// 清除计时器
clearInterval(timeId);
this.value="点名";
};
}; // 获取时间的函数
getTime();
setInterval(getTime,)
function getTime(){
var day = new Date();
var year = day.getFullYear();//年
var month = day.getMonth()+;//月
var dat = day.getDate();//日
var hour = day.getHours();//小时
var minitue = day.getMinutes();//分钟
var second = day.getSeconds();//秒
month=month<?""+month:month;
dat=dat<?""+dat:dat;
hour=hour<?""+hour:hour;
minitue=minitue<?""+minitue:minitue;
second=second<?""+second:second;
my$("span").innerText=year+"-"+month+"-"+dat+" "+hour+":"+minitue+":"+second
} </script>
</body>
</html>
方法二:
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style type="text/css">
body{
background: #f5faff;
}
.ks{
width: 140px;
line-height: 55px;
text-align: center;
font-weight: bold;
color: #fff;
text-shadow:2px 2px 2px #;
border-radius: 5px;
margin: 20px 20px ;
position: relative;
overflow: hidden;
background-color: limegreen;
border:1px solid #d2a000;
box-shadow: 1px 2px #fedd71 inset, -1px #a38b39 inset, -2px 3px #fedd71 inset;
}
#nu{
background-color: red;
}
#div1 { font:40px '微软雅黑';text-align: center; background-color: gainsboro;
width: %;
height: %;
margin-bottom:20px;
}
</style>
</head>
<body>
<form>
<div align="center">
<input type="button" value="开始点菜" onclick="students()" class="ks"/>
<input type="button" value="停止点菜" onclick="stop()" class="ks" id="nu"/>
<hr color="blue">
<br>
<div id="div1" align="center">随机点菜区域</div>
</div>
</form>
<script type="text/javascript">
var i = ;
//t用来接收setTimeOut()的返回值
var t;
var st = ["麻辣烫", "不吃了", "爱吃不吃", "盖饭", "面条"];
var u;
//点菜函数
function students()
{
//顺序点菜
/* if (i < st.length)
{
u = st[i];
}
else
{
//点到最后一个就回来重新点起
i = 0;
u = st[i];
}
i = i + 1;
*/
//随机点名 产生0-数组长度之间的数作为数组下标
var num = Math.floor(Math.random()*st.length);
u = st[num];
//更改文本框显示的value值
document.getElementById("div1").innerHTML = u ;
t = setTimeout("students()", );
}
//停止点菜函数
function stop()
{
clearTimeout(t);
}
</script>
</body>
</html>
JS 同一标签随机不停切换数据点菜--解决选择困难症的更多相关文章
- js模拟form表单提交数据, js模拟a标签点击跳转,避开使用window.open引起来的浏览器阻止问题
js模拟form表单提交数据, js模拟a标签点击跳转,避开使用window.open引起来的浏览器阻止问题 js模拟form表单提交数据源码: /** * js模拟form表单提交 * @param ...
- js使用s:property标签接收json格式数据
js使用s:property接收json数据时,会出现字符被转译的错误. 错误如下: 引号会被转译成'"'字符,导致解析不了. 错误原因: html的s:property接收不会出错,而js ...
- js(jquery)鼠标移入移出事件时,出现闪烁、隐藏显示隐藏显示不停切换的情况
<script> $(".guanzhu").hover(function(){ $(".weixinTop").show(); },functio ...
- 优化 html 标签 为何能用HTML/CSS解决的问题就不要使用JS?
优化 html 标签 2018年05月11日 08:56:24 阅读数:19 有些人写页面会走向一个极端,几乎页面所有的标签都用div,究其原因,用div有很多好处,一个是div没有默认样式,不会有m ...
- angular input标签只能单向传递数据的问题
angularjs input标签只能单向传递数据的问题 <ion-view title = "{{roomName}}" style = "height:90%; ...
- Gremlins.js – 模拟用户随机操作的 JS 测试库
Gremlins.js 是基于 JavaScript 编写的 Monkey 测试库,支持 Node.js 平台和浏览器中使用.Gremlins.js 随机模拟用户操作:单击窗口中的任意位置,在表格中输 ...
- RandomUser – 生成随机用户 JSON 数据的 API
RandomUser 是一个 API,它为您提供了一个或者一批随机生成的用户.这些用户可以在 Web 应用程序原型中用作占位符,将节省您创建自己的占位符信息的时间.您可以使用 AJAX 或其他方法来调 ...
- [jQuery编程挑战]007 切换数据表格的行列
<!DOCTYPE html> <html lang="zh"> <head> <meta charset="utf-8&quo ...
- 关于js渲染网页时爬取数据的思路和全过程(附源码)
于js渲染网页时爬取数据的思路 首先可以先去用requests库访问url来测试一下能不能拿到数据,如果能拿到那么就是一个普通的网页,如果出现403类的错误代码可以在requests.get()方法里 ...
随机推荐
- js非常强大的日历控件fullcalendar.js, 日期时间库: moment.js
日历控件: https://fullcalendar.io/docs/ https://fullcalendar.io/docs/event_data/events_function/ https:/ ...
- vue.js $refs和$emit 父子组件交互
父调子 $refs (把父组件的数据传给子组件) <template> <div id="app"> <input type="butto ...
- 每日英语:Proactive Advice for Dealing With Grief: Seek Out New Experiences
When her husband died of cancer 10 years ago, Becky Aikman says she experienced grief and adapted to ...
- 每日英语:The Toy Mogul Who Became A Billionaire Through His Fight To The Death With Barbie
The trophy case in the tiny conference room outside Isaac Larian’s corner office spans an entire wal ...
- linux下配置某程序的sudo不用输密码
$ su密码: # cd /etc/# cp sudoers sudoers_bak# vi sudoers 最下面加入一行:ALL ALL = NOPASSWD:/usr/sbin/openconn ...
- CSAPP 读书笔记 - 2.31练习题
根据等式(2-14) 假如w = 4 数值范围在-8 ~ 7之间 2^w = 16 x = 5, y = 4的情况下面 x + y = 9 >=2 ^(w-1) 属于第一种情况 sum = x ...
- 【转帖】(一)unity4.6Ugui中文教程文档-------概要
原帖至上,移步请戳:(一)unity4.6Ugui中文教程文档-------概要 unity4.6中的一个重要的升级就是GUI ,也把它称为UGUI ,废话我不多说,大家可以百度了解一下. 虽然现在处 ...
- 【ARM】2440裸机系列-图片显示
功能 LCD显示字汉字,字符和图片 说明 汉字,字符和图片需要用相应的取模软件得到相应的c文件,然后包含到工程中 主要代码 1)绘制背景 void Brush_ U32 c) { int x,y ...
- 本地存储localStorage以及它的封装接口store.js的使用
本地存储localStorage以及它的封装接口store.js的使用 sublime-text chrome javascript readyGo 2016年11月20日发布 0 推荐 9 收藏 ...
- 利用canvas绘制序列帧动画
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...