JSON ツリーを「検索」するための 3 つの入力フィールドがあります。3 つのフィールドすべてが入力され、正しい場合は、次の JSON レベルからデータを取得します。
JSON ツリーの次のデータを取得するために、keyup イベントで数値をカウントアップします。ただし、3 つのフィールドすべてが満たされるたびに、カウンターはリセットされます。
HTML
<h1>sein</h1>
<form>
<input type="text" id=simple_present placeholder="simple present">
<input type="text" id=simple_past placeholder="simple past">
<input type="text" id=past_participle placeholder="past participle">
</form>
<div class="answer">Enter: be - was - been</div>
JS
$('input').on('keyup', function() {
var count = 0;
if (this.value === json.verbs.irregular[count++][this.id]) {
$(this).prop('disabled', true).next().focus();
}
if ($('input:not(:disabled)').length === 0) {
$('input').val('').prop('disabled', false).first().focus();
$('h1').text(json.verbs.irregular[count++].infinitiv);
alert(count);
}
});
おそらく、キーイベントごとに変数が 0 に設定されるでしょうか? しかし、私はそれをkeyup
-event の外に設定することはできません!
これは、私がこれまでに行ったことのデモンストレーションです。
次のように入力します。
- なれ
- だった
- その間
何か案は?