【问题标题】:how to make text able to copy in ionic App如何使文本能够在 ionic App 中复制
【发布时间】:2020-08-24 23:58:39
【问题描述】:

我想制作一个能够在 ionic App 中复制的文本。我试过这个How to allow copy and paste from an ionic webview? 解决方案。但这对我不起作用。请给我一个解决方案的建议。

【问题讨论】:

    标签: ios iphone ionic-framework


    【解决方案1】:

    在 .css 文件中尝试以下代码。

    .selectable {
      -webkit-user-select: text;
      -moz-user-select: text;
      -ms-user-select: text;
      user-select: text;
    }
    

    【讨论】:

    • 您是否在适当的标签中将 css 类设置为 .html 文件?
    • 可选对html的影响在默认css中没有这个名称的类
    • 表示 class="selectable" 在您的 ionic webview 中。我不告诉它的默认类。
    • 我没有使用 webview
    • 您使用哪个控件来实现此功能?
    【解决方案2】:

    尝试应用这些样式。

    在您的 CSS 文件中:

    ion-content{
      overflow-scroll: true;
    }
    
    .scroll-content {
      -webkit-user-select: auto !important;
      -moz-user-select: auto !important;
      -ms-user-select: auto !important;
      user-select: auto !important;}
    
    .selectable {
      -webkit-user-select: auto;
    }
    

    在您的控制器中

     stop_browser_behavior: false
      
    self.touchStart = function(e) {
      self.startCoordinates = getPointerCoordinates(e);
    
      if ( ionic.tap.ignoreScrollStart(e) ) {
        return;
      }
    
      if( ionic.tap.containsOrIsTextInput(e.target) ) {
        // do not start if the target is a text input
        // if there is a touchmove on this input, then we can start the scroll
        self.__hasStarted = false;
        return;
      }
    
      self.__isSelectable = true;
      self.__enableScrollY = true;
      self.__hasStarted = true;
      self.doTouchStart(e.touches, e.timeStamp);
      // e.preventDefault();
    };
    

    然后在您的 HTML 中:

    <div class='selectable'>
          This text should be selectable
    </div>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-11-26
      • 1970-01-01
      • 2021-05-07
      • 1970-01-01
      • 2021-11-15
      • 2013-01-11
      • 1970-01-01
      相关资源
      最近更新 更多