在文本输入字段上模拟退格键 [英] simulate backspace key on text input field
问题描述
有人可以提供一个很好的例子来模拟< INPUT>
文本字段上的退格键吗?
我需要在HTML5中使用虚拟键盘,并且只需要在 Webkit 浏览器中使用。
注释:
nofollow的> http://jsfiddle.net/dan_barzilay/WWAh7/2/
如果您需要更多解释注释,get caret函数用于知道删除角色的位置。
重置游标函数用于在退格后恢复插入位置。
**它使用jquery,但您可以将其更改为正常的js, / p>
Can someone provide a good example to simulate the backspace key on a <INPUT>
text field?
I need this for a virtual keyboard done in HTML5 and it only needs to work in Webkit browsers.
Notes:
createEvent
/initTextEvent
/dispatchEvent
with charcode 8 (backspace) is being ignored (that seems to work only for printable characters)- changing manually the
value
usingsubstr()
sort of works, but this way the caret moves to the end of the input field (and I want to be able to delete characters in the middle of the input field, just like when using a normal keyboard).
Alright here you go: http://jsfiddle.net/dan_barzilay/WWAh7/2/
The get caret function is used to know where to delete the character, if you need more explaining comment. The reset cursor function is used to restore the caret position after the backspacing.
**it's using jquery but you can change it to normal js in secounds
这篇关于在文本输入字段上模拟退格键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!