Я делаю мобильную клавиатуру.У меня были проблемы с JavaScript.Я знаю, что у меня есть ошибка в JavaScript, потому что клавиатура не печатает.Это мой JavaScript:
$(function() {
var $write = $('#write'),
shift = false,
capslock = false; // This code is imported from Jquery.
// It defines 3 variables, textarea, a shift status, and a caps lock status.
$('#keyboard li').click(function() { //This code creates 2 variables when a character is clicked (Not a symbol ).
var $this = $(this),
character = $this.html(); // If it's a lowercase letter, nothing happens to this variable
// Code for processing the key press.
});
});
// Shift key
if ($this.hasClass('left-shift') || $this.hasClass('right-shift')) { // If the shift key is pressed,(The shift key is left or right shift) we togle the uppercase value of each letter.
$('.letter').toggleClass('uppercase'); //This code calls the leter to be uppercase.
$('.symbol span').toggle(); //Nothing happens if it is a symbol.
shift = (shift === true) ? false : true; // This code sets the shift key to the opposite boolean. (If shift key= false, set it to true.)
capslock = false; // capslock is not enabled.
return false; // If you hit return, the shift key switches off and makes the shift key false.
}
// Caps lock
if ($this.hasClass('capslock')) {
$('.letter').toggleClass('uppercase'); //This code gets the letters you type in and toggles their class to uppercase.
capslock = true; //This code sets the capslock button to true.
return false; // If you hit return, the caps capslock button is false and turns of.
}
// Delete
if ($this.hasClass('delete')) { //This Code happens when hit the delete button.
var html = $write.html(); // This code defines the variable HTML to the write vairiable.HTML, which gets the letters you typed in earlier.
$write.html(html.substr(0, html.length - 1)); //This code makes the delete button delete. The number 0 defines that it deletes the previous number and the number -1 takes away part of the string typed by the user.
return false;
// Special characters
if ($this.hasClass('symbol')) character = $('span:visible', $this).html(); //This code sets the symbol charactes' spam to visable, and gets what the characters look like from the HTML that I have typed in earlier.
if ($this.hasClass('space')) character = ' '; //Makes a space bettween characters and symbols typed by the user.
if ($this.hasClass('tab')) character = "\t" // This code uses the \t metaCharacter which finds a tab character. It returns the number in the string of where the character was found, and if the user has not typed anything, it returns -1)
if ($this.hasClass('return')) character = "\n"; // This code uses the \n metaCharacter. If return is pressed, the computer located the user to another line. If there are no more lines, it stays on the same line.
// Uppercase letters
if ($this.hasClass('uppercase')) character = character.toUpperCase(); // This code defines the uppercase method and the toUpperCase method. If you have clicked shift or caps lock, it toggles the uppercase class. It would not work for me so I did some rechearch. I figured out that you need to add the toUpperCase method. The method sets any strings typed and sets the class to uppercase. (I defeined the classes in the index.HTML file.)
// Remove shift once a key is clicked.
if (shift === true) { //This code happenes when shift is true. (Shift is true when it is pressed.)
$('.symbol span').toggle(); //This code happens when a symbol is pressed when shift is on
if (capslock === false) $('.letter').toggleClass('uppercase'); // This code happens when capsLock is false and the shift key is pressed. After a character is pressed with the shift key, the shift is set to false.
shift = false; //Sets the shift key to false.
}
// Add the character
$write.html($write.html() + character); //This code is the last code. It finally adds any of the characters/ symbols. The keyboard is now just a regular keyboard.
});
});
Может кто-нибудь, пожалуйста, помогите мне?Я перепробовал все, что мог, но не смог заставить его работать.Если кому-то нужны дополнительные сведения, пожалуйста, дайте мне знать