我一直在尝试创建一个Wordle型游戏,但是我不知道如何从可满足的Div中获得用户输入。我想发生的事情是,如果用户输入字母“ a”,则DIV中的字母会变绿,而另一个Div中的其他字母是不同的颜色。
因此,基本上,当用户完成每个字母的键入以猜测时,他们会单击输入,字母“ a”将变绿。 (在这种情况下,这个词是绝对的)
另外,如果可能的话,请确保用户实际上在使功能成为可能之前填写了行中的所有框。
let word = "absolute";
function inputFunc() {
event.target.nextElementSibling.focus();
}
document.getElementById('amo1').addEventListener('keypress', function(e) {
document.getElementById('amo1').value = this.innerHTML;
});
这是我在JSFIDDLE中的完整代码,包括所有Divs,CSS,HTML和JS代码:
I have been trying to create a wordle-type game, but I don't know how to get the user input from the contenteditable div's. What I want to happen is if the user inputs the letter 'a' for example, the letter in the div would turn green, whilst the other letters in the other div's are a different color.
So basically, when the user is done typing in every letter for a guess, they would click enter and the letter 'a' would turn green. (The word in this case would be absolute)
Also if possible making sure the user actually fills out all the boxes in the row before making the function possible.
let word = "absolute";
function inputFunc() {
event.target.nextElementSibling.focus();
}
document.getElementById('amo1').addEventListener('keypress', function(e) {
document.getElementById('amo1').value = this.innerHTML;
});
Here is my full code in JSFiddle, including all the divs, CSS, HTML and JS code: https://jsfiddle.net/Infui/c7q30gez/1/
发布评论
评论(1)
https://codepen.io/codmitu/pen/pen/pen/pen/lyegznn?editors=0011
html:
JS:
https://codepen.io/codmitu/pen/LYegzNN?editors=0011
html:
js: