我正在使用 asp:button 使用 Java 脚本为触摸屏创建一个带有 A-Z 和 0-9 的键盘。该键盘与一个文本框链接。如果我们点击一个按钮,相应的文本就会显示在文本框中。它工作正常。我已使用 jquery JQuery Autocomplete 将自动完成功能包含到此文本框中.
问题:
- 如果我的用户定义键盘,自动完成功能将不起作用。 如何将我的按键修改为键盘按键[设置事件键码]?是否可以?还有其他方法可以实现这一目标吗?
代码:
<asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>
<asp:Button ID="zero" runat="server" Text="0" CssClass="myclass" OnClientClick="return typeLetter(this);" TabIndex="20"/>
function typeLetter(currentbutton) {
if (previousActiveElement != null) {
if (previousActiveElement == 'antSearchText'){
var position = document.getElementById('position').value;
if (position == '') {
alert('chk position');
} else {
var existingString = document.getElementById(previousActiveElement).value;
var beforeString = existingString.substring(0, position);
var afterString = existingString.substring(position, existingString.length);
document.getElementById(previousActiveElement).value = beforeString + currentbutton.value + afterString;
setCaretPosition(document.getElementById(previousActiveElement), parseInt(position) + 1);
setCaretPosition(document.getElementById(previousActiveElement), parseInt(position) + 1);
}
}
}
return false;
}
编辑:
在自动完成插件中,以下是获取按键事件,如何使用我的按键传递相同的按键事件?
$input.bind(($.browser.opera ? "keypress" : "keydown") + ".autocomplete", function(event) {
}
最佳答案
尝试手动触发 jQuery keydown/keyup 事件。我一辈子都不记得哪个自动完成功能会触发,但要点是:
// your documment.getElementById(...)
jQuery('#'+previousActiveElement).keyup();
// your setCaretPosition
尝试不同的按键事件,其中一个应该会导致自动完成功能启动。
希望有帮助!
谢谢, 乔
关于javascript - 自动完成和用户定义键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2598981/