我正试图从字段外部触发jquery自动完成。
我运行的是屏幕上的jquery键盘,因此不会触发正常的keyup-keydown事件。
我不能使用jquery.event或trigger(),因为我一直使用jquery 1.2.6。
我知道屏幕上还有其他键盘,但我测试过的其他键盘都有“延迟”。字段选择增加了一点,但这是相当快的。只是…无自动完成点火。
我并没有超过滚动我自己的自动完成,但其余的代码是如此简单,我只是想确保我没有错过一些简单的东西。:)
FieldSelection是一个经过修改的版本,支持从这里退格:
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>