【发布时间】:2019-04-21 20:00:05
【问题描述】:
这个应用程序是教孩子们葡萄牙语。但是我遇到了麻烦,因为它成功输入了所有英文字符但是当重音字符出现时我得到一个错误
<div class="ui segment segment-container">
<div class="label-container">
<label id="label" class="word"></label>
</div><br />
<div class="ui input">
<input id="key" type="text" placeholder="Type here">
</div><br />
<div class="icon-container correct"> You got it right! <i class="check icon"></i></div>
<div class="icon-container wrong">Oops! This seems wrong <i class="x icon"></i></div>
<div class="icon-container success">Success <i class="thumbs up outline icon"></i></div>
</div>
<script>
$(document).ready(function () {
$('.correct').hide();
$('.wrong').hide();
$('.success').hide();
$('#key').hover();
var randomKey = Math.floor((Math.random() * 6))
var labels = ["the pencil is red", "the car is blue", "the sky is blue", "the grass is green", "he has a red clock", "i have a yellow box"];
$('#label').html(labels[randomKey]).toString().toLowerCase();
var label = $('#label').html().toString().toLowerCase();
var counter = 0;
$("#key").keyup(function (e) {
var code = e.which || e.keyCode;
var enteredLetter = String.fromCharCode(code).toLowerCase().toString();
if (code !== 8 && code !== 46 && code !== 13 && code !==16) {
if (label[counter] === enteredLetter) {
$('.correct').fadeIn();
$('.wrong').hide();
$('.success').hide();
++counter;
if (counter === label.length) {
counter = 0;
$('.correct').hide();
$('.wrong').hide();
$('#key').val('');
$('.success').fadeIn();
randomKey = Math.floor((Math.random() * 6));
$('#label').html(labels[randomKey]).toString().toLowerCase();
label = $('#label').html().toString().toLowerCase();
}
}
else {
$('.correct').hide();
$('.wrong').fadeIn();
$('.success').hide();
var dataEntered = $('#key').val().toString();
$('#key').val(dataEntered.slice(0, -1));
}
}
});
});
</script>
输入的字母是一个一个字符并检查它。但是当重音字符是类型时(按下两个键)它说它是错误的。
【问题讨论】:
标签: javascript