帖子
帖子
用户
博客
课程
显示全部楼层
51
帖子
1
勋章
617
Y币

[App引擎] JS长按复制文本

[复制链接]
发表于 2016-6-24 03:08:25
本帖最后由 cysell 于 2016-6-24 03:13 编辑

HTML:

<div     ontouchstart="gtouchstart(this)"           ontouchmove="gtouchmove()"      ontouchend="gtouchend()"    >要复制的文字</div>


JS:

                        var timeOutEvent = 0;
                        var copytext = '';
                        function gtouchstart(obj) {
                                copytext = obj.innerText;
                                timeOutEvent = setTimeout("longPress()", 600);
                                return false;
                        }

                        function gtouchend() {
                                clearTimeout(timeOutEvent);
                                timeOutEvent = 0;
                                return false;
                        }

                        function gtouchmove() {
                                clearTimeout(timeOutEvent);
                                timeOutEvent = 0;
                                return false;
                        }

                        function longPress() {
                                timeOutEvent = 0;
                                var clipBoard = api.require('clipBoard');
                                clipBoard.set({
                                        value : copytext
                                }, function(ret, err) {
                                        if (ret) {
                                                api.toast({
                                                        msg : '文字复制成功',
                                                        duration : 1500,
                                                        location : 'bottom',
                                                        global : true
                                                });
                                        } else {
                                        }
                                });
                        }







50
帖子
0
勋章
190
Y币
感谢分享,还是想做一个类似选择复制的
51
帖子
1
勋章
617
Y币
水木易安 发表于 2016-6-24 03:23
感谢分享,还是想做一个类似选择复制的

改成弹出菜单,选择复制

                      function longPress() {
                                timeOutEvent = 0;
                                api.actionSheet({
                                        cancelTitle : '取消',
                                        buttons : ['复制文字']
                                }, function(ret, err) {
                                        if (ret) {
                                                if (ret.buttonIndex == 1) {
                                                        var clipBoard = api.require('clipBoard');
                                                        clipBoard.set({
                                                                value : copytext
                                                        }, function(ret, err) {
                                                                if (ret) {
                                                                        api.toast({
                                                                                msg : '复制成功',
                                                                                duration : 1500,
                                                                                location : 'bottom',
                                                                                global : true
                                                                        });
                                                                } else {
                                                                }
                                                        });
                                                }
                                        } else {
                                        }
                                });
                        }
11
帖子
0
勋章
90
Y币
null is not an object(evaluating'clipBoard.set') 苹果上出现这样的提示 为什么
51
帖子
1
勋章
617
Y币
hjl758 发表于 2016-11-9 10:14
null is not an object(evaluating'clipBoard.set') 苹果上出现这样的提示 为什么

引入模块,编译后可用
11
帖子
0
勋章
90
Y币
cysell 发表于 2016-11-9 13:49
引入模块,编译后可用

要正式版?? 我也云编译过测试版 也是这个提示  
5
帖子
0
勋章
3281
Y币
hjl758 发表于 2016-11-9 14:00
要正式版?? 我也云编译过测试版 也是这个提示

在云端上你没添加这个模块?
11
帖子
0
勋章
90
Y币
nvwong 发表于 2016-11-9 14:21
在云端上你没添加这个模块?

是什么模块
1
帖子
0
勋章
387
Y币
貌似不能选择部分文字复制呀,只能说全部复制这样
您需要登录后才可以回帖 登录

本版积分规则