点名小功能
作者:互联网
<!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>
标签:功能,span,name,arr,randomNum,var,点名,btn 来源: https://www.cnblogs.com/a155-/p/12234998.html