早上好,
我只是接近我的结果,我在控制台上出错了
1.write不是一个函数 2. $ write.val不是函数
如何解决此错误我如何在我的代码中编写函数。如何$ write.val不是定义它的函数以及我如何解决这种类型的错误。
这是代码
$(function() {
/*$(":input").map((i, el) => el.id).get(),*/
//var abc = abc();
//var abc;
var $write = $(":input").bind('focus', function() {
$write = $(this).attr('id');
//console.log(Object.values($write));
//console.log($write);
//});
//var test=abc(); // this will grab you the return value from firstFunction();
//alert(test);
var $write = $write;
shift = false,
capslock = false;
alert($write);
//console.log(Object.values($write));
$('#keyboard li').click(function() {
var $this = $(this),
character = $this.html(); // If it's a lowercase letter, nothing happens to this variable
// Shift keys
if ($this.hasClass('left-shift') || $this.hasClass('right-shift')) {
$('.letter').toggleClass('uppercase');
$('.symbol span').toggle();
shift = (shift === true) ? false : true;
capslock = false;
return false;
}
// Caps lock
if ($this.hasClass('capslock')) {
$('.letter').toggleClass('uppercase');
capslock = true;
return false;
}
// Delete
if ($this.hasClass('delete')) {
var html = $write.html(),
txt = html.substr(0, html.length - 1);
$write.html(txt);
$write.autocomplete("search", txt);
return false;
}
// Special characters
if ($this.hasClass('symbol')) character = $('span:visible', $this).html();
if ($this.hasClass('space')) character = ' ';
if ($this.hasClass('tab')) character = "\t";
if ($this.hasClass('return')) character = "\n";
// Uppercase letter
if ($this.hasClass('uppercase')) character = character.toUpperCase();
// Remove shift once a key is clicked.
if (shift === true) {
$('.symbol span').toggle();
if (capslock === false) $('.letter').toggleClass('uppercase');
shift = false;
}
// Add the character
$write.val($write.val() + character);
$write.html(txt);
$write.autocomplete("search", txt);
});
});
});
这是代码的其余部分
$(function () {
var write = write();
write.init("keyboard");
//first input focus
var $firstInput = $(":input").first().focus();
write.currentElement = $firstInput;
write.currentElementCursorPosition = 0;
});