编程语言
首页 > 编程语言> > Javascript点名器

Javascript点名器

作者:互联网

通过Javascript实现每次刷新随机点名效果

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    
</head>
<style>
    /* 用css修改样式 */
    div{
        margin: 200px auto;
        width: 200px;
        height: 70px;
        background-color: burlywood;
        text-align: center;
        font-size: 30px;
        font-weight: bold;
        line-height: 70px;
        color: white;
        background-image:  url(../../html+css/img/古代喜庆图案中国风.jpg);
        background-size: 100%;
    }
</style>
<body>
    <div id="roll" ></div>
</body>
<script>
    //引入html的id
    var roll=document.getElementById("roll");
    //将名字添加到字符串内
    var RollCallIs=["张三","李四","王二","小昭","小刚","小明"];
    //用随机索引值实现随机点名  Math.floor返回小于RollCallIs的最大整数,
    var ranRoll=RollCallIs[Math.floor(Math.random()*RollCallIs.length)];
    //添加到HTML内
    roll.innerHTML=ranRoll;
</script>
</html>

标签:点名,Javascript,background,var,roll,Math,RollCallIs
来源: https://blog.csdn.net/xxc_yc/article/details/111180333