我是 JS 新手。我放入document.getElementById
我的 JS 并尝试将该元素放入一个p
id 中,但是当我单击按钮时,什么都没有显示。我在这里做错了什么?任何帮助是极大的赞赏。谢谢!
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>GRL Example</title>
<script>
function class_roll() {
// Car Classes
var classes = ["B", "A", "S", "R3", "R2", "R1"],
classToUse = classes[Math.floor(Math.random() * classes.length)];
var elemClass = document.getElementById("croll");
}
function track_roll() {
// Tracks
var tracks = ["Clear Springs Circuit", "Festival North Circuit", "Beaumont Circuit", "Finley Dam Circuit", "Gladstone Circuit", "Clifton Valley Trail", "Gladstone Trail"],
trackToUse = tracks[Math.floor(Math.random() * tracks.length)];
var elemTrack = document.getElementById("troll");
}
</script>
</head>
<body>
<p id="croll">Some text here</p>
<button onclick="class_roll();">Class Roll</button>
<p id="troll">Some text here</p>
<button onclick="track_troll;">Track Roll</button>
</body>
</html>