Javascript 点击Android后,输入立即失去焦点
我试图解决一个问题,在Android手机上,当我点击输入框时,它会立即失去焦点。我正在使用TwitterTypeahead库为输入框供电 事件链是:Javascript 点击Android后,输入立即失去焦点,javascript,jquery,mobile,twitter-typeahead,Javascript,Jquery,Mobile,Twitter Typeahead,我试图解决一个问题,在Android手机上,当我点击输入框时,它会立即失去焦点。我正在使用TwitterTypeahead库为输入框供电 事件链是: 单击(轻触)我的输入框 输入框瞬间获得焦点,并触发单击事件 输入框失去焦点 以下是我尝试过的: 在单击处理程序中使用preventDefault和preventPropogation myInput.on('click', function(e){ e.preventDefault(); e.preventPropo
preventDefault
和preventPropogation
myInput.on('click', function(e){
e.preventDefault();
e.preventPropogation();
});
myInput.on('click', function(e){
myInput.focus()
// setTimeout(function() { myInput.focus() }, 250); // or this
});
myInput.on('click',函数(e){
e、 预防默认值();
e、 预防传播();
});
结果:无效果(输入框仍失去焦点)
2。在单击处理程序中触发焦点事件
myInput.on('click', function(e){
e.preventDefault();
e.preventPropogation();
});
myInput.on('click', function(e){
myInput.focus()
// setTimeout(function() { myInput.focus() }, 250); // or this
});
myInput.on('click',函数(e){
myInput.focus()
//setTimeout(function(){myInput.focus()},250);//或
});
结果:同上
有人有其他解决方案供我尝试吗?我刚刚修复了一个类似的问题,只在绝对需要脚本的页面上添加了一个导致问题的脚本(jquery jscrollpane) 此外,还有一个位置为的div:fixed导致了一个问题。我在css中的div中添加了以下内容:
.top-bar {
position: fixed;
top: 0;
left: 0;
z-index: 5;
width: 100%;
height: 60px;
background-color: white;
/* Add these below. Important part. */
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
}
最后,两天后,问题得到了解决。我刚刚修复了一个类似的问题,只在绝对需要脚本的页面上包含了导致问题的脚本(jquery jscrollpane) 此外,还有一个位置为的div:fixed导致了一个问题。我在css中的div中添加了以下内容:
.top-bar {
position: fixed;
top: 0;
left: 0;
z-index: 5;
width: 100%;
height: 60px;
background-color: white;
/* Add these below. Important part. */
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
}
最后,两天后,问题得到了解决。键盘也消失了吗?你在使用jquery mobile吗?我遇到了完全相同的问题。我整天都在和它斗争。iOS上的键盘是否保持打开状态?我的问题只在Android上。另外,您会使用jquery jscrollpane库吗?@tsteve是的,它说在iOS上打开。我们只使用snap.js。我们一个不是it@a53-是的,很奇怪。也许我下面的答案会有帮助。键盘也会消失吗?你在使用jquery mobile吗?我也有同样的问题。我整天都在和它斗争。iOS上的键盘是否保持打开状态?我的问题只在Android上。另外,您会使用jquery jscrollpane库吗?@tsteve是的,它说在iOS上打开。我们只使用snap.js。我们一个不是it@a53-是的,很奇怪。也许我下面的答案会有所帮助。