输入文本时在线键盘禁用

发布于 2024-11-26 05:15:52 字数 1917 浏览 0 评论 0原文

我正在使用本教程中的稍微增强的虚拟键盘:

http://net.tutsplus.com/tutorials/javascript-ajax/creating-a-keyboard-with-css-and-jquery/

Jquery:

$(function(){
var $write2 = $('#write2'),
    shift = false,
    capslock = false;

$('#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 = $write2.html();

        $write2.html(html.substr(0, html.length - 1000));
        return false;
    }

    // Special characters
    if ($this.hasClass('symbol')) character = $('span:visible', $this).html();
    if ($this.hasClass('space')) character = $('span:visible', $this).html();
    if ($this.hasClass('tab')) character = $('span:visible', $this).html();
    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
    $write2.html(character+ "  " + $write2.html());
    }); });

问题是,当我手动更改时这文本区域,键盘被禁用。我不太确定为什么,并且教程并没有真正解释该错误。

谢谢。

I'm using a slightly augmented virtual keyboard from this tutorial:

http://net.tutsplus.com/tutorials/javascript-ajax/creating-a-keyboard-with-css-and-jquery/

The Jquery:

$(function(){
var $write2 = $('#write2'),
    shift = false,
    capslock = false;

$('#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 = $write2.html();

        $write2.html(html.substr(0, html.length - 1000));
        return false;
    }

    // Special characters
    if ($this.hasClass('symbol')) character = $('span:visible', $this).html();
    if ($this.hasClass('space')) character = $('span:visible', $this).html();
    if ($this.hasClass('tab')) character = $('span:visible', $this).html();
    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
    $write2.html(character+ "  " + $write2.html());
    }); });

The problem is, when I manually change the textarea, the keyboard gets disabled. I'm not really sure why and the tutorial didn't really explain that bug.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

删除→记忆 2024-12-03 05:15:52

尝试使用 val 而不是 html

$write.val($write.val() + character)

try using val instead of html

$write.val($write.val() + character)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文