jQuery UI自动完成IE光标位置错误 [英] jQuery UI Autocomplete IE Cursor Position Bug

查看:72
本文介绍了jQuery UI自动完成IE光标位置错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚实现了出色的jQuery UI自动完成功能.

I have just implemented the excellent jQuery UI autocomplete.

http://jqueryui.com/demos/autocomplete/

IE 8(甚至其他版本)中存在一个奇怪的错误.

There is a strange bug in IE 8 (and maybe other versions).

当您从IE 8的建议框中选择一个项目时,光标将移动到文本框的开头,在刚插入的建议单词之前.

When you select an item from the box of suggestions in IE 8 the cursor moves to the begining of the textbox before the suggested word which has just been inserted.

Firefox将光标置于插入的单词之后.

Firefox put the cursor after the inserted word.

有人知道此修复程序吗?

Does anyone know of a fix for this?

致谢

史蒂夫

推荐答案

尝试将以下代码添加到传递给autocomplte函数的select事件中.

Try adding the following code into the select event that is passed to the autocomplte function.

所以,如果您有:

jQuery('someval').autocomplete({
        source: availableTags
    });

将其更改为:

jQuery('some_val').autocomplete({
    source: availableTags,

    select : function(event, ui){
            if(document.selection) { 
                this.focus(); 
                var oSel = document.selection.createRange(); 
                oSel.moveStart('character',this.value.length); 
                oSel.moveEnd('character',0); 
                oSel.select(); 
            } 
        }
})

查看更多: http://forum.jquery.com/主题/用户界面的自动完成多个演示插入符位置 http://jqueryui.com/demos/autocomplete/#multiple

这篇关于jQuery UI自动完成IE光标位置错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆