编辑**
在我的文字游戏中,有一个带有 3 个字母单词的网格。
游戏的目的是通过单击侧面的相应字母来拼写单词。
当网格中的某个区域被突出显示时,它会向用户指示要拼写的单词。用户单击网格一侧的字母,它们会移动到突出显示的区域。
单击一个字母时,它将动画到网格中的相应区域。我想让它尽可能地对用户友好,所以我想另外添加“keyDown()”,以便当用户按下“a”时它会在屏幕上显示动画。
字母像这样存储在 HTML 中
<div class="tiles-wrapper">
<div id="drag1" class="drag ui-widget-content player-tiles2" tabindex="0" data-letter="a">
<p>a</p>
</div>
<div id="drag2" class="drag ui-widget-content player-tiles" tabindex="0" data-letter="b">
<p>b</p>
</div>
<div id="drag3" class="drag ui-widget-content player-tiles" tabindex="0" data-letter="c">
<p>c</p>
</div>
<div id="drag4" class="drag ui-widget-content player-tiles" tabindex="0" data-letter="d">
<p>d</p>
</div>
<div id="drag5" class="drag ui-widget-content player-tiles2" tabindex="0" data-letter="e">
<p>e</p>
</div>
<div id="drag6" class="drag ui-widget-content player-tiles" tabindex="0" data-letter="f">
<p>f</p>
</div>
<div id="drag7" class="drag ui-widget-content player-tiles" tabindex="0" data-letter="g">
<p>g</p>
</div>
<div id="drag8" class="drag ui-widget-content player-tiles" tabindex="0" data-letter="h">
<p>h</p>
</div>
<div id="drag9" class="drag ui-widget-content player-tiles2" tabindex="0" data-letter="i">
<p>i</p>
</div>
<div id="drag10" class="drag ui-widget-content player-tiles" tabindex="0" data-letter="j">
<p>j</p>
</div>
<div id="drag11" class="drag ui-widget-content player-tiles" tabindex="0" data-letter="k">
<p>k</p>
</div>
<div id="drag12" class="drag ui-widget-content player-tiles" tabindex="0" data-letter="l">
<p>l</p>
</div>
<div id="drag13" class="drag ui-widget-content player-tiles" tabindex="0" data-letter="m">
<p>m</p>
</div>
<div id="drag14" class="drag ui-widget-content player-tiles" tabindex="0" data-letter="n">
<p>n</p>
</div>
<div id="drag15" class="drag ui-widget-content player-tiles2" tabindex="0" data-letter="o">
<p>o</p>
</div>
<div id="drag16" class="drag ui-widget-content player-tiles" tabindex="0" data-letter="p">
<p>p</p>
</div>
<div id="drag17" class="drag ui-widget-content player-tiles" tabindex="0" data-letter="q">
<p>q</p>
</div>
<div id="drag18" class="drag ui-widget-content player-tiles" tabindex="0" data-letter="r">
<p>r</p>
</div>
<div id="drag19" class="drag ui-widget-content player-tiles" tabindex="0" data-letter="s">
<p>s</p>
</div>
<div id="drag20" class="drag ui-widget-content player-tiles" tabindex="0" data-letter="t">
<p>t</p>
</div>
<div id="drag21" class="drag ui-widget-content player-tiles2" tabindex="0" data-letter="u">
<p>u</p>
</div>
<div id="drag22" class="drag ui-widget-content player-tiles" tabindex="0" data-letter="v">
<p>v</p>
</div>
<div id="drag23" class="drag ui-widget-content player-tiles" tabindex="0" data-letter="w">
<p>w</p>
</div>
<div id="drag24" class="drag ui-widget-content player-tiles" tabindex="0" data-letter="x">
<p>x</p>
</div>
<div id="drag25" class="drag ui-widget-content player-tiles" tabindex="0" data-letter="y">
<p>y</p>
</div>
<div id="drag26" class="drag ui-widget-content player-tiles" tabindex="0" data-letter="z">
<p>z</p>
</div>
我有一些脚本,但我不知道如何将其链接起来
$(document).keypress(function(e){
if (e.which >= 97 && e.which <= 122) {
animateDrag(String.fromCharCode(e.which));
}
});