此图片描述了我的问题。
早上好, 实际上,我正在使用键盘插件。它对单个输入框很有用。因为如果从中获取直接ID(' itemNo_2'),则其值为' id'我已经服用了。但是,如果我们采取('输入')而不是(' itemNo_2'),那么事情发生在这里。键入一个输入框可在所有输入框中获取文本
请给我一些建议。我花了太多时间,但我没有一个好的解决方案。
$(function(){
var $write = $(':input'),
shift = false,
capslock = false;
backspace = false;
$('#keyboard li').click(function(){
var $this = $(this),
character = $this.html();
// Shift keys
if ($this.hasClass('left-shift') || $this.hasClass('right-shift')) {
$('.letter').toggleClass('uppercase');
$('.symbol span').toggle();
shift = (shift === true) ? false : true;
capslock = false;
backspace = false;
return false;
}
// Caps lock
if ($this.hasClass('capslock')) {
$('.letter').toggleClass('uppercase');
capslock = true;
return false;
}
// backspace lock
if ($this.hasClass('backspace')) {
$('.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;
}
// Delete
// 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;
}
//console.log("DO IT ", character);
// 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;
});