我接近我的结果但是我得到了一些id,现在我一次发送一个光标输入框。 我在控制台上显示了一系列id 看看
我怎么只得到一个'iD'。你在图像中看到很多东西,但我只想要一个我的光标聚焦的id。
$(function(){
var $write = $( "input[type=text]" ).focus(function() {
shift = false,
capslock = false;
backspace = false;
console.log(Object.values($write));
$('#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);
});
});
});
答案 0 :(得分:0)
问题有点令人困惑,但我会试一试:
console.log(Object.values($write));
,你打印的是所选对象的所有值,而不仅仅是id。只打印对象id的语法是:console.log($myObject.attr('id'));