1. 效果:
2. HTML代码:
3. JavaScript代码:
函数
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()",1000);
}
//停止点名函数
function stop()
{
clearTimeout(t);
}
4. CSS代码:
Box-shadow: 0 1px 2px #fedd71 inset,0 -1px 0 #a38b39 inset,0 -2px 3px #fedd71 inset;
}
#nu{
background-color: red;
}
#div1 { font:40px '微软雅黑';text-align: center; background-color: gainsboro;
width: 60%;
height: 60%;
margin-bottom:20px;
}
以上所述是小编给大家介绍的JS实现课堂随机点名和顺序点名。编程之家 jb51.cc 收集整理的教程希望能对你有所帮助,如果觉得编程之家不错,可分享给好友!感谢支持。