此应用程序旨在向儿童教授葡萄牙语。但是我遇到麻烦,因为它无法成功输入所有英文字符,但是当带重音符号的字符出现错误
<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>
输入的字母正在一个字符一个接一个地检查。但是当输入带重音符号的字符(按下两个键)时,它表示这是错误的。
答案 0 :(得分:0)
在HTML页面的标题上尝试以下操作:
<!DOCTYPE html>
<html lang="pt">
<head>
<meta charset="utf-8">
,并确保同时保存ut8编码的html。
也许可以解决问题,就像对Portuguese charset problem这个问题所做的那样。