zoukankan      html  css  js  c++  java
  • 微信小程序-点击复制功能

    wxml:

    <view class="page">
      <view class="template flex-col" wx:for="{{templateList}}" wx:key="{{templateList}}" wx:for-index='idx'>
        <view class="title">{{item.Title}}</view>
        <view class="content">{{item.TemplateText}}</view>
        <view class="copy flex-center" bindtap='copyBtn' data-idx='{{idx}}'>复制</view>
      </view>
    </view>

    js:

    //点击一键复制
    copyBtn: function (e) {
        var that = this;
        //当前索引
        var currentidx = e.currentTarget.dataset.idx;
        console.log(currentidx); 
    
        wx.setClipboardData({
          //准备复制的数据内容
          data: that.data.templateList[currentidx].TemplateText,
          success: function (res) {
            wx.showToast({
              title: '复制成功',
            });
          }
        });
    },

    备注:

    如果想长按复制,那就在 text 中设置 selectable="true

    <view class="content">
      <text selectable='true' bindlongtap='copyBtn'>
        {{item.TemplateText}}
      </text>
    </view>
  • 相关阅读:
    regedit注册表
    Environment应用
    VMI帮助类
    Image帮助类
    asp.net core+Postman
    printf和cout的区别详述
    C++指针
    Qt button和buttons区别
    visual studio收函数
    编译警告
  • 原文地址:https://www.cnblogs.com/joe235/p/13321080.html
Copyright © 2011-2022 走看看