我创建了一个 javascript 程序,当您单击标题“单击此处”时,该程序从我的数组中逐个打印元素,我的问题是尝试实现一个函数,当您单击单词时从 html 页面中删除一个随机单词以前打印但它打印其他单词,我如何创建一个删除以前打印的单词的函数?
<!DOCTYPE html>
<html>
<head>
<title>function JavaScript</title>
<script >
var k = 0;
var ph = ["red ","blue","black","green","yellow"];
function text(){
if(k < ph.length ){
document.getElementById("test").innerText+=" "+ ph[k];
k++;
}
}
function deleteWord(){
var number = Math.floor(Math.random() * 5);
document.getElementById("test").innerText+=" "+ ph[number];
}
</script>
</head>
<body>
<h1 onclick="text();">Click here</h1>
<span id="test" onclick="deleteWord();"></span>
</body>
</html>