标签:cti 功能 ack 插入 mat dom random title div
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <h1>点到的名字:<span></span></h1> <button>点名</button> <script type="text/javascript"> var arr=["章子怡","王菲","李小璐","孙燕姿"] var btn=document.querySelector("button") btn.onclick=function(){ var randomNum=parseInt(Math.random()*arr.length) var name=arr[randomNum] var span =document.querySelector("span") //innerHTML在JS是双向功能:获取对象的内容 或 向对象插入内容,在这里是向span里插入变量name span.innerHTML=name } </script> </body> </html>
标签:cti 功能 ack 插入 mat dom random title div
原文地址:https://www.cnblogs.com/a155-/p/12234998.html