在 1.2.6 上通过脚本事件触发 Jquery 自动完成

发布于 2024-08-23 05:37:19 字数 1763 浏览 3 评论 0原文

我正在尝试从字段外部触发 Jquery 自动完成。

我正在运行屏幕上的 Jquery 键盘,因此不会触发正常的 keyup keydown 事件。

我无法使用 Jquery.Event 或 trigger() 因为我坚持使用 Jquery 1.2.6。

我知道还有其他屏幕键盘,但我测试过的所有其他键盘都有“滞后”。 fieldselection 增加了一点,但这相当快。只是..没有自动完成触发。

我不会放弃自己的自动完成功能,但其余的代码非常简单,我只是想确保我不会错过一些简单的东西。 :)

fieldselection 是一个修改版本,支持退格键:http://designshack.co.uk/教程示例/vkeyboard/

<script type="text/javascript" src="js/jquery.fieldselection.js"></script>
<script type="text/javascript">
$(document).ready(function() {
// Keeps track of last input that was clicked in.
    $('input[type="text"], textarea').focus(function() {
        selectedInput = $(this);
    });
    // Add autocomplete.
    $('#search-customers-input').autocomplete(
      'js/ps-action.php?searchCustomers=1');
    // Attach action to virtual keyboard keys.
    $('.keypad-literal').click(function() {
        selectedInput.replaceSelection($(this).text(), true);
        // I don't chain these as for some reason it doesn't work.
        selectedInput.focus();
        // Can't use as I'm on 1.2.6
        //var key = $(this).text(); 
        //var e = jQuery.Event("keydown");
        //e.which = key.charCodeAt(0);
        //selectedInput.trigger(\'focus\').trigger(e);
    });
});
</script>
<button type=button class="keypad-key keypad-literal">q</button>
<button type=button class="keypad-key keypad-literal">w</button>
<button type=button class="keypad-key keypad-literal">e</button>
... etc ...
<button type=button class="keypad-key large"
  onClick='selectedInput.parents("form").submit();'>Enter</button>

I'm attempting to trigger Jquery autocomplete from outside the field.

I'm running an on screen Jquery keyboard, so the normal keyup keydown events are not fired.

I can not use Jquery.Event or trigger() because I'm stuck with Jquery 1.2.6.

I am aware there are other onscreen keyboards out there, but all the other ones I've tested have 'lag'. fieldselection adds a little, but this was reasonably fast as is. Just.. no autocomplete firing.

I'm not above rolling my own autocomplete, but the rest of the code is so simple and I just want to make sure I'm not missing something simple. :)

fieldselection is a modified version that supports backspace from here: http://designshack.co.uk/tutorialexamples/vkeyboard/

<script type="text/javascript" src="js/jquery.fieldselection.js"></script>
<script type="text/javascript">
$(document).ready(function() {
// Keeps track of last input that was clicked in.
    $('input[type="text"], textarea').focus(function() {
        selectedInput = $(this);
    });
    // Add autocomplete.
    $('#search-customers-input').autocomplete(
      'js/ps-action.php?searchCustomers=1');
    // Attach action to virtual keyboard keys.
    $('.keypad-literal').click(function() {
        selectedInput.replaceSelection($(this).text(), true);
        // I don't chain these as for some reason it doesn't work.
        selectedInput.focus();
        // Can't use as I'm on 1.2.6
        //var key = $(this).text(); 
        //var e = jQuery.Event("keydown");
        //e.which = key.charCodeAt(0);
        //selectedInput.trigger(\'focus\').trigger(e);
    });
});
</script>
<button type=button class="keypad-key keypad-literal">q</button>
<button type=button class="keypad-key keypad-literal">w</button>
<button type=button class="keypad-key keypad-literal">e</button>
... etc ...
<button type=button class="keypad-key large"
  onClick='selectedInput.parents("form").submit();'>Enter</button>

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

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

发布评论

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

评论(1

作业与我同在 2024-08-30 05:37:19

你尝试过jQuery.noConflict()吗?
(此处的文档:http://api.jquery.com/jQuery.noConflict/

<script type='text/javascript' src='jquery-1.4.2.min.js'></script>
<script type='text/javascript'>
    // create namespace for jquery 1.4.2
    var j142 = $.noConflict(true);
</script>
<script type='text/javascript' src='jquery-1.2.6.min.js'></script>

<script type='text/javascript'>
    // jquery 1.4.2 codes here
    j142(document).ready(function() {
        j142('p#new').text('jquery 1.4.2 yay!');
        });

    // jquery 1.2.6 codes here, falling back to the default $
    $(document).ready(function() {
        $('p#old').text('jquery 1.2.6 yay!');
        });
</script>

have you try jQuery.noConflict()?
(docs here: http://api.jquery.com/jQuery.noConflict/)

<script type='text/javascript' src='jquery-1.4.2.min.js'></script>
<script type='text/javascript'>
    // create namespace for jquery 1.4.2
    var j142 = $.noConflict(true);
</script>
<script type='text/javascript' src='jquery-1.2.6.min.js'></script>

<script type='text/javascript'>
    // jquery 1.4.2 codes here
    j142(document).ready(function() {
        j142('p#new').text('jquery 1.4.2 yay!');
        });

    // jquery 1.2.6 codes here, falling back to the default $
    $(document).ready(function() {
        $('p#old').text('jquery 1.2.6 yay!');
        });
</script>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文