Google Chrome 取消向上和向下箭头事件
我正在为网站制作一个 AutoSuggest 小部件,其工作方式是,当用户在输入文本框中写入内容时,会显示带有建议的 div,并且用户可以通过鼠标或向上和向下箭头进行导航。每个单词都是单独建议的(不像 Google 建议中它在整个短语中的样子)。
我的 Google Chrome 输入框有问题,因为当我按向上或向下箭头时,浏览器会出现默认行为 - 用插入符跳转到文本框的结尾或开头(如“主页”或“结束”按钮) 在 Firefox 或 Internet Explorer 上没有这种效果 我如何
从事件处理函数返回“false” ?这里的函数 http://www.javascripter.net/faq/canceleventbubbling.htm 但仍然卡雷特在跳跃在 Chrome 上...
编辑:在 Safari 上效果相同...
I'm making an AutoSuggest widget for a website, which works in the way that when an user writes something in input text box the div with suggestions is displayed and an user can navigate through it by mouse or by up and down arrows. Each word is suggested separately (not like in Google suggest where it looks on the whole phrase.
I have a problem with Google Chrome input box as when I'm pressing up or down arrow there is a default behaviour of browser - jump with carret to the end or beginning of the text box (like with Home or End buttons). There is no such effect on Firefox or Internet Explorer. How could I disable this effect?
I'm returning 'false' from the event handler function and also used a function from here http://www.javascripter.net/faq/canceleventbubbling.htm but still carret is jumping on Chrome...
Edit: same effect on Safari...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否尝试过阻止默认行为?
Have you tried preventing the default behavior?
不完全是问题的真正解决方案,但我已经使用此函数完成了解决方法
http://blog.vishalon。 net/index.php/javascript-getting-and-setting-caret-position-in-textarea/
并在事件之前捕获插入符位置(或者不完全在触发 keydown 事件之前,因为触发事件时插入符仍处于良好位置),然后在事件之后将其设置回原位。
Not exatly a true solution for a question but I've done a workaround by using this functions
http://blog.vishalon.net/index.php/javascript-getting-and-setting-caret-position-in-textarea/
and catching the carret position before event (or not exatly before as when keydown event is fired the carret is still on good position) and then setting it back after event.