本文实例为大家分享了Javascript实现随机点名小程序的具体代码,供大家参考,具体内容如下
导入jar包
将jquery-3.3.1.min.js包导入到web目录下的js包
代码实现
点名器 body{ background-color: gray; } .box{ width: 1000px; height: 280px; margin: 0 auto; margin-top: 100px; clear: both; } #btn,#btn2,#btn3,#btnStop{ width: 150px; height: 50px; margin-top: 50px; font-size: 18px; } .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; } .high{ background-color: #FFDEAD; font-weight:500; } 随机点名系统
小结
1.div元素使用循环动态生成,循环长度是名单数组的长度
2.div生成后要添加box到父元素中
3.Math.random()随机数为0-10以内的小数.随机范围为数组的长度
4.在生成名单颜色时需要清除之前的颜色
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持考高分网。



