gpt4 book ai didi

javascript - 从单击的按钮获取值

转载 作者:行者123 更新时间:2023-11-29 21:53:52 25 4
gpt4 key购买 nike

我正在我的屏幕上创建一个键盘。现在,当通过函数 getLetter 单击时,我正在取回每个字母的值,但我需要获取该值并使用它而不是 prompt()[0]。所以我希望我的输入是实际的字母(“A”或“B”或...)。问题是我无法将该值放入输入变量中。我该怎么做?

abc = ['A','B','C','D','E','F','G','H','I','J','K','L','M',
'N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];

$('#letters').text('');
for (i = 0; i < 26; i++) {
var div = $('<div>').css( 'cursor', 'pointer' );
div.html(abc[i]);
div.on('click', getLetter);
var newDiv = $('#letters').append(div);
}
$('body').append(newDiv);


function getLetter() {
$(this).text();
this.innerHTML = '&nbsp;';
this.style.cursor = 'default';
this.onclick = null;
}

while(!game.isOver()) {
var input = prompt()[0];
game.guess(input);
$('p').text(game.render());
}

最佳答案

您可以将 while 循环的内容移动到 getLetter() 函数中,并删除 while 循环,因为它现在没用了:在用户单击 a 之前您不想做任何事情按钮。

function getLetter() {
var input=$(this).text();
this.innerHTML = '&nbsp;';
this.style.cursor = 'default';
this.onclick = null;
game.guess(input);
$('p').text(game.render());
}

关于javascript - 从单击的按钮获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27530856/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com