【问题标题】:.select() function does not work on iOS device [duplicate].select() 函数在 iOS 设备上不起作用 [重复]
【发布时间】:2013-03-05 01:09:46
【问题描述】:

我想做一个输入框,当用户选择它时,框中的所有文本都会被选中。所以我决定使用select() 函数,这是我想要实现的。但是,它在桌面浏览器上可以正常工作,但在 iPad 上的 Safari 上却不行。如何解决问题?谢谢。

$('#input').click(function(e){
      $(this).select();
});

【问题讨论】:

  • 我在那里尝试了解决方案,但它不起作用。感谢您的提醒。

标签: javascript jquery html mobile mobile-safari


【解决方案1】:

根据这个 SO question(Programmatically selecting text in an input field on iOS devices (mobile Safari)),它在 iOS 中不起作用,您需要使用 setSelectionRange() 函数。在你的情况下,它会是这样的:

$(this).get(0).setSelectionRange(0,9999);

【讨论】:

  • 这就是答案,谢谢
猜你喜欢
  • 1970-01-01
  • 2018-09-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-21
  • 1970-01-01
  • 2014-10-10
  • 1970-01-01
相关资源
最近更新 更多