标签:none var element name 效果 区分 inter body style
<style>
#oname{width: 300px;height: 100px;border: 1px solid black;border-radius: 50px;display: block;margin: 100px auto;text-align: center;line-height: 150px;font-size: 32px;outline:none;}
#btn{width: 300px;height: 100px;border:none;border: 1px solid black;border-radius: 50px;display: block;margin: 200px auto;text-align: center;line-height: 100px;outline:none;font-size: 32px;}
</style>
<body>
<input type="text" id="oname" readonly>
<input type="button" value="随机点名" id="btn">
</body>
var oname = document.getElementById(‘oname‘);
var btn = document.body.children[1];
var ns = [‘张三‘,‘张怡‘,‘张呈双‘,‘家蒴‘,‘张智轩‘,‘智杰‘,‘泽城‘,‘张垣涛‘,‘嵓张国漾‘,‘张家朔‘,‘张国杨‘,‘李四‘,‘亿斌‘,‘张澍‘];```
var t;
var onoff = 0; // 0是开
oname.value = ‘张三‘; //设定一开始名字框内的内容
btn.onclick = function () {
if(onoff == 0){
t = setInterval(function(){
var i = Math.round(Math.random()*(ns.length-1));
oname.value = (ns[i]);
oname.style.background = randomColor();
},100);
onoff = 1;
}else{
clearInterval(t);
onoff = 0;
}
}
标签:none var element name 效果 区分 inter body style
原文地址:https://www.cnblogs.com/wangya6/p/14477573.html