javascript - html中的填字游戏
问题描述
这个小拼图只接受小写字母。
请问如何让它接受大写和小写字母?
或者至少提醒用户停用大写锁定?
HTML
<body onload="initializeScreen()">
<table id="puzzle">
</table>
<input class="butt" type="submit" value="Check" onclick="checkClicked()">
JS
//Loads the Crossword
function initializeScreen(){
var puzzleTable = document.getElementById("puzzle");
puzzleArrayData = preparepuzzleArray();
for ( var i = 0; i < puzzleArrayData.length ; i++ ) {
var row = puzzleTable.insertRow(-1);
var rowData = puzzleArrayData[i];
for(var j = 0 ; j < rowData.length ; j++){
var cell = row.insertCell(-1);
if(rowData[j] != 0){
var txtID = String('txt' + '_' + i + '_' + j);
cell.innerHTML = '<input type="text" class="inputBox" maxlength="1" style="text-transform: uppercase" ' + 'id="' + txtID + '" onfocus="textInputFocus(' + "'" + txtID + "'"+ ')">';
}
}
}
addHint();
}
//Returns Array
function preparepuzzleArray(){
var items = [[0, 'f', 0],
['r', 'u', 'n'],
[0, 'n', 0],
];
return items;
}
//Check button
function checkClicked(){
for ( var i = 0; i < puzzleArrayData.length ; i++ ) {
var rowData = puzzleArrayData[i];
for(var j = 0 ; j < rowData.length ; j++){
if(rowData[j] != 0){
var selectedInputTextElement = document.getElementById('txt' + '_' + i + '_' + j);
if(selectedInputTextElement.value != puzzleArrayData[i][j]){
selectedInputTextElement.style.backgroundColor = 'pink';
}else{
selectedInputTextElement.style.backgroundColor = 'lightgreen';
}
}
}
}
}
一旦前一个输入达到其最大长度值,我还想让焦点自动转到下一个输入?那可能吗?
解决方案
在测试大写锁定方面,您可以说
const puzzle = document.getElementById('#puzzle');
puzzle.addEventListener('keyup', function (event) {
let caps = event.getModifierState('CapsLock');
if(caps){
alert("Please turn off caps lock etc..")
}
})
推荐阅读
- sql - 在 dateadd 中添加天数,但需要使用 sql 查询格式“dd/mm/yyyy hh:mm:ss tt”
- javascript - 拇指滑块如何在 html 中工作?
- sublimetext - 在 Sublime Text 4 中隐藏内联错误(幻象)
- java - 在 android 上使用 gluon-mobile 运行 apk 文件时出错
- python - 如何有条件地从熊猫数据框中的多个日期时间列中选择第一个非空日期?
- c++ - 在热图像中检测微亮区域(鹿的小鹿)
- angular - Angular - 错误 TS2532:对象可能是“未定义”。103 事件.preventDefault;
- css - 如何设置编辑器列表样式的 cjk-decimal css?
- php - PHP 将公式更改为图像公式
- gramex - 在 Gramex 中跨 API 保存数据