焦点/单击时是否可以选择iphone设备上的所有输入文本?
通常对于浏览器环境,人们会使用:
$('input').bind("click focus", function() {
$(this).select();
});
这适用于桌面浏览器,但对于 iphone 和可能的其他移动设备似乎没有响应。
焦点/单击时是否可以选择iphone设备上的所有输入文本?
通常对于浏览器环境,人们会使用:
$('input').bind("click focus", function() {
$(this).select();
});
这适用于桌面浏览器,但对于 iphone 和可能的其他移动设备似乎没有响应。
基本上你必须重新排列事件焦点,然后单击,然后触摸启动
$('#myID').on('focus click touchstart', function(e){
$(this).get(0).setSelectionRange(0,9999);
//$(this).css("color", "blue"); FUBAR
e.preventDefault();
});
设置(小)超时最适合我:iOS 键盘似乎是在委托或其他东西中调用的,因为它不断失去我的焦点事件才能选择东西。由于select()
同样的原因,它没有工作。
我这样修复它:
function focusMe(vitem) {
window.setTimeout(function() {
vitem.setSelectionRange(0, 9999);
}, 10);
}
<input onfocus="focusMe(this)" />
$('input[type="text"]').on('focus',function(){
$(this).get(0).selectionStart=0;
$(this).get(0).selectionEnd=999;
})
我最初在这里找到了这个信息,还有其他人尝试过的事情已经达到了结果。
我会使用这样的东西:
$('input').live("click", function() {
$('input').each(function(){
$(this).select();
});
});
$('input').live("focus", function() {
$('input').each(function(){
$(this).select();
});
});