在 1.2.6 上通过脚本事件触发 Jquery 自动完成
我正在尝试从字段外部触发 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你尝试过
jQuery.noConflict()
吗?(此处的文档:http://api.jquery.com/jQuery.noConflict/)
have you try
jQuery.noConflict()
?(docs here: http://api.jquery.com/jQuery.noConflict/)