在 iPhone 上的移动 Safari 中选择文本

2024-04-15移动开发问题
5

本文介绍了在 iPhone 上的移动 Safari 中选择文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我试图让 iphone 用户可以轻松地将一些文本复制到移动 safari 中的剪贴板.就像通常的触摸保持复制"一样.我希望用户复制一段特定的文本.我可以完全选择用于包装文本的 html 标记.我怎样才能让它变得容易,而不是随意?例如:

I'm trying to make it easy for an iphone user to copy some text to the clipboard in mobile safari. As in the usual "touch-hold-copy". There is a specific bit of text I want to a user to copy. I have full choice of the html markup in which to wrap the text. How can I make it easy, rather than abitrary? For instance:

  • 有没有办法在使用 javascript 触地时全选"文本?那么用户可以继续长按然后选择复制吗?

  • Is there a way to "select all" the text upon touch-down using javascript? Then a user could just continue to touch-hold and then choose copy?

有没有办法调出全选"选项?就像在文本框中输入时一样?之后他们可以选择复制?

Is there a way to bring up the "select all" option? Like you can when typing in a text box? After which they can choose copy?

如果没有 javascript 解决方案,我该如何安排 html 以帮助 Safari 轻松选择正确的文本位?而不是一个词,或者一个包装的 div?

If there's no javascript solution, how can I arrange the html to help Safari select the right bit of text easily? As opposed to just a word, or a wrapping div?

我已经为各种元素尝试过 onFocus="this.select()" ,但似乎都不起作用.也试过onClick.

I've tried onFocus="this.select()" for various elements, none seem to work. Also tried onClick.

那些尝试将使用 ZeroClipboard 的网站移植到 iPhone 上的人可能会有一些想法.

Those who have tried to port a site that uses ZeroClipboard to the iPhone might have some ideas.

干杯

推荐答案

而不是 this.select(); 我使用了以下,它成功了!

instead of this.select(); I used the following and it worked!

this.selectionStart=0;
this.selectionEnd=this.value.length;

这篇关于在 iPhone 上的移动 Safari 中选择文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

硬件音量按钮更改应用程序音量
Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)...
2024-08-12 移动开发问题
10

Cocos2d - 如何检查不同层中对象之间的交集
Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)...
2024-08-12 移动开发问题
8

突出显示朗读文本(在 iPhone 的故事书类型应用程序中)
Highlight Read-Along Text (in a storybook type app for iPhone)(突出显示朗读文本(在 iPhone 的故事书类型应用程序中))...
2024-08-12 移动开发问题
9

Cocos2D + 仅禁用 Retina iPad 图形
Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)...
2024-08-12 移动开发问题
10

正确的 cocos2d 场景重启?
Proper cocos2d scene restart?(正确的 cocos2d 场景重启?)...
2024-08-12 移动开发问题
7

[ios.cocos2d+box2d]如何禁用自动旋转?
[ios.cocos2d+box2d]how to disable auto-rotation?([ios.cocos2d+box2d]如何禁用自动旋转?)...
2024-08-12 移动开发问题
7