我是初学者javascript,我们在 uni 的任务hangman game是input fields在html form. 我想使用 anevent listener来显示一个submit按钮all the input fields are filled,当我想删除一个字母时,按钮显然必须消失。我在下面编写了代码,根据给定单词的字母大小在表单容器中显示输入字段。我的(ex. word = "hi" => 2 input fields to fill for "hi" )问题是我不知道如何创建此 eventListener 函数,我将感谢您对此的帮助。
我的代码:
function hangman(){
var island = "Rhodes"; //the given word that is supposed to be found
var t = document.createTextNode(shuffleWord(island))
document.getElementById("hidden-word").appendChild(t);
createSpaces(island);
}
function shuffleWord (word){
var shuffledWord = '';
word = word.split('');
while (word.length > 0) {
shuffledWord += word.splice(word.length * Math.random() << 0, 1);
}
return shuffledWord;
}
function createSpaces(text){
for(var i=0;i<text.length;i++){
var space = document.createElement("input");
space.setAttribute("class" , "dash");
document.getElementById("hangman-container").appendChild(space);
}
}
body, html {
background-size: cover;
}
body{
margin: 0;
}
.transparent-box{
border:none;
position:absolute;
top:10%;
left:15%;
background-color:black;
height:500px;
width:70%;
opacity: 0.6;
}
.transparent-box p{
color:white;
text-align:center;
}
.transparent-box h1{
color:white;
position: relative;
text-align:center;
font-size:20px;
top:30px;
}
#hangman-container{
display: block;
position: relative;
width:auto;
top:30%;
left:0%;
background-color: transparent;
display: flex;
flex-direction: row;
justify-content: space-evenly;
}
.dash{
margin:0;
align-items: flex-start;
width:5%;
border:none;
border-radius: 5%;
background-color: turquoise;
color:red;
font-size:30px;
}
.dash:focus{
opacity:0.8;
}
#submitbtn{
display:none;
position: absolute;
top:200%;
left:80%;
float:right;
}
这个词是一个随机字符串,你必须在上面的代码中猜出正确的词。先感谢您 。
拉莫斯之舞
噜噜哒
LEATH
相关分类