今天做项目的时候,突然发现在chrome下,input光标上下移动会移到开始位置(悲剧~).
不知道是chrome的bug还是他本身的问题.
详细介绍:
我们平时做自动搜索,会有下拉提示,此时,需要用到up arrow and down arrow,
这里要用到↑↓两个箭头,
经测试在IE6,7,8,9,FF都正常的情况.
唯独chrome个显风骚,
于是google了下,发觉确实有很多说法, 和解决方案.
目前我采取的方案如下:
// set focus position and fix Chrome
function moveEnd(obj){
if($.browser.safari){//判断chrome 或者 Safari 这个是一致的
var len = obj[0].value.length,
setTimeFocus;
if(setTimeFocus!= null) window.clearTimeout(setTimeFocus);
setTimeFocus = window.setTimeout(function(){
if (typeof obj[0].selectionStart == 'number' && typeof obj[0].selectionEnd == 'number') {
obj[0].selectionStart = obj[0].selectionEnd = len;
}
},1);}
}
这里要注意, 控制在1毫秒时间,来缓冲,要不然,根本看不到效果,起先我还以为这个有问题.后来才发现速度太快引起的.
欢迎大家发表其它的方案,
此方案也有缺陷.仅供参考;
loading