在iPhone上的移动Safari中选择文字 [英] Selecting text in mobile Safari on iPhone

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

问题描述

我想让一个iphone用户可以轻松地将一些文本复制到移动safari中的剪贴板。如通常的触摸 - 保持复制。有一个特定位的文本我想要用户复制。我有完全选择的html标记,在其中包装文本。我如何使它容易,而不是abitrary?例如:




  • 有没有办法使用javascript来触摸时全选文本?然后,用户可以继续触摸保持,然后选择复制?


  • 有没有办法打开全选选项?喜欢你可以在文本框中输入吗?

  • 如果没有javascript解决方案,如何安排html帮助Safari轻松选择正确的文本?




我试过onFocus =this.select ),对于各种元素,没有人似乎工作。也尝试了onClick。



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



干杯

解决方案

而不是 this.select(); 我使用以下和它的工作!

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


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:

  • 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?

  • 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?

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

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

Cheers

解决方案

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

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

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

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