使用jQuery在焦点上选择文本不能在iPhone iPad浏览器中工作 [英] Selecting text on focus using jQuery not working in iPhone iPad Browsers
本文介绍了使用jQuery在焦点上选择文本不能在iPhone iPad浏览器中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们正在为移动浏览器开发Web-App,我们希望每当输入框获得焦点时,都会选择任何输入框的文本。以下答案解决了Desktop Chrome / Safari浏览器的问题。下面的解决方案可以在Android浏览器上正常工作,但不能在iPhone / iPad浏览器上使用任何解决方案..
We are developing Web-App for Mobile browsers, we would like text of any input box to get selected whenever input-box get focus. Below answer fixes the issue for Desktop chrome/safari browser. Below solution works fine on Android browser, but not on iPhone/iPad browsers, any solution..
$("#souper_fancy").focus(function() { $(this).select() });
$("#souper_fancy").mouseup(function(e){
e.preventDefault();
});
参考: -
使用jQuery在焦点上选择文本不工作在Safari和Chrome
推荐答案
在这里找到的答案
不知道如何将此问题标记为重复。
以编程方式选择文本iOS设备上的输入字段(移动版Safari)
我的修正如下所示: -
My fix look like this:-
<script type="text/javascript">
$('div,data-role=page').live('pageshow', function (event) {
jQuery.validator.unobtrusive.parse(".ui-page-active form");
$("input[type='text'], textarea, input[type='password'], input[type='number']").live('mouseup', function (e) { e.preventDefault(); });
$("input[type='text'], textarea, input[type='password'], input[type='number']").live('focus', function () {this.setSelectionRange(0, 9999); });
});
</script>
这篇关于使用jQuery在焦点上选择文本不能在iPhone iPad浏览器中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文