小程式裡點選按鈕複製文案
阿新 • • 發佈:2018-12-18
index.js程式碼
Page({
/* 頁面的初始資料 */
data: {
order_ids: "http://t.cn/Rgh0o1T"
},
// 一鍵複製事件
copyBtn: function (e) {
var that = this;
wx.setClipboardData({
//準備複製的資料
data:that.data.order_ids,
success: function (res) {
wx.showToast({
title: '複製成功',
});
}
});
}
})
index.wxml中程式碼
<!-- 標籤名稱 -->
<text selectable='true' bindlongtap='copy'>{{order_ids}}</text>
<!-- 複製 -->
<label class='lab_copy' bindtap='copyBtn'>複製</label>
注:如果單純是長按複製文案,直接在text中加入一個selectable='true'屬性就行