我正在尝试使用JavaScript创建子手游戏,但是,我遇到了一个问题,即试图让页面加载时随机生成的名称。任何建议,将不胜感激!请查看代码。<!DOCTYPE html><html><head></head><body> <p id='movie-title'></p> <footer> </footer></body></html>var movieTitles = [ "Halloween", "Suspiria", "Audition", "Hereditary", "The Beyond", "The Evil Dead", "The Blair Witch Project"];function randomMovieTitle(movie) { return "Movie Title:"+ " " + movie;}document.getElementById("movie-title").innerHTML = randomMovieTitle("Halloween");我也尝试过moviesToGuess = movieTitles[Math.floor(Math.random() * movieTitles.length)];“万圣节”所在的位置document.getElementById("movie-title").innerHTML = randomMovieTitle("Halloween");但我无法随机生成它,我一直在尝试我们document.getElementById("movie-title").onload = function() {randomMovieTitle()};页面加载。为了使页面在页面加载时随机生成电影标题之一。
添加回答
举报
0/150
提交
取消