以编程方式在 iOS 设备(移动 Safari)的输入字段中选择文本 [英] Programmatically selecting text in an input field on iOS devices (mobile Safari)

查看:33
本文介绍了以编程方式在 iOS 设备(移动 Safari)的输入字段中选择文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 iOS 设备上以编程方式选择输入字段的文本,例如运行移动版 Safari 的 iPhone、iPad?

How do you programmatically select the text of an input field on iOS devices, e.g. iPhone, iPad running mobile Safari?

通常在 <input .../> 元素上调用 .select() 函数就足够了,但这在这些设备上不起作用.光标只是留在现有条目的末尾,不进行任何选择.

Normally it is sufficient to call the .select() function on the <input ... /> element, but this does not work on those devices. The cursor is simply left at the end of the existing entry with no selection made.

推荐答案

input.setSelectionRange(0, 9999);

https://developer.mozilla.org/en/DOM/Input.select

这篇关于以编程方式在 iOS 设备(移动 Safari)的输入字段中选择文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆