【问题标题】:How to capture selectionStart and selectionEnd in Safari for ios?如何在 Safari for ios 中捕获 selectionStart 和 selectionEnd?
【发布时间】:2018-11-21 23:18:09
【问题描述】:

我们有一个组件允许用户保存我们网站上某些文本的亮点。它在我们所有其他浏览器中都可以正常工作,但在 ios 的 Safari 中,它不会捕获任何选择。

我们使用的是 Vue,这是表单字段的代码。你可以看到我们对@select.native 事件的反应。

<b-form-textarea
    v-show="!highlight || editing"
    v-model="highlightableText"
    @select.native="selectText"
    :readonly="true"
    :no-resize="true"
    rows="10"
    ref="highlightable_textarea"
    class="ubcgs-highlightable-text"
>
</b-form-textarea>

selectText方法是这样的:

selectText(e) {
    this.selecting = true;
    this.selectionStart = e.target.selectionStart;
    this.selectionEnd = e.target.selectionEnd;
},

在我的 iPhone 上,我可以以通常的方式选择一些文本,复制它,然后将其粘贴到另一个窗口中。但是,据我所知,永远不会调用 selectText 方法。例如,this.selecting 为 true 时显示一个单独的文本区域,它不显示。

我发现的各种答案和博客似乎表明这种方法应该可行,但它们是几年前的事情,Apple 喜欢比这更经常地改变事情。是否有其他我应该听的事件,或者其他方式来获得选择?

【问题讨论】:

    标签: ios vue.js textarea mobile-safari


    【解决方案1】:

    我发现添加事件“touchend”是有效的。工作版本:

    <b-form-textarea
        v-show="!highlight || editing"
        v-model="highlightableText"
        @select.native="selectText"
        @touchend.native="selectText"
        :readonly="true"
        :no-resize="true"
        rows="10"
        ref="highlightable_textarea"
        class="ubcgs-highlightable-text"
    >
    </b-form-textarea>
    

    【讨论】:

      猜你喜欢
      • 2013-10-17
      • 2015-04-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-06
      • 1970-01-01
      相关资源
      最近更新 更多