JS实现 分享视频中-->点击button(copy),复制对应网址

本文介绍了一种简单方法,在HTML页面上通过点击按钮轻松复制视频的网址和嵌入代码,适用于YouTube和Vimeo平台。

分享视频中-->点击button(copy),复制对应网址


HTML页面代码

<input type="text" class="share-input" value="http://www.youtube.com" id="copy-content"/>
<button class="copy-button" type="button" onclick="copyContent();"> Copy </button>
<p> Embed </p>
<input type="text" class="share-input" value="http://www.vimeo.com" id="copy-embed"/>
<button class="copy-button" type="button" onclick="copyEmbed();"> Copy </button>


JS代码

    /*Copy function implementation */
    function copyContent(){ 
        var copyobject=document.getElementById("copy-content");
        copyobject.select();
        document.execCommand("Copy");
        alert("has been copied you can paste"); 
    };
    
    function copyEmbed(){ 
        var copyobject=document.getElementById("copy-embed");
        copyobject.select(); 
        document.execCommand("Copy"); 
        alert("has been copied you can paste"); 
    };


效果图

页面效果图


点击Copy按钮


<template> <view class="container"> <!-- 顶部图片 --> <image src="/static/E-mailForComplaint.png" class="header-image" mode="widthFix" ></image> <!-- 投诉邮箱板块 --> <view class="complaint-card"> <text class="card-title">其亚投诉邮箱</text> <!-- 邮箱信息 --> <view class="info-item"> <view class="icon-container"> <text class="icon">✉️</text> </view> <view class="info-content"> <text class="info-label">邮箱:</text> <text class="info-value">2412077392@qq.com</text> </view> </view> <!-- 地址信息 --> <view class="info-item"> <view class="icon-container"> <text class="icon">📍</text> </view> <view class="info-content"> <text class="info-label">地址:</text> <text class="info-value">上海市浦东新区世纪大道1777号东方希望大厦16楼</text> </view> </view> <!-- 操作按钮 --> <view class="action-buttons"> <button class="action-btn copy-btn" @tap="copyEmail"> <text class="btn-icon">📋</text> <text class="btn-text">复制邮箱</text> </button> <button class="action-btn mail-btn" @tap="sendEmail"> <text class="btn-icon">✉️</text> <text class="btn-text">发送邮件</text> </button> </view> </view> <!-- 底部说明 --> <view class="footer"> <text class="footer-text">我们将在收到邮件核实后回及时复您</text> <text class="footer-text">工作日9:00-19:00</text> </view> </view> </template> <script setup> import { ref } from 'vue'; // 复制邮箱功能 const copyEmail = () => { uni.setClipboardData({ data: '2412077392@qq.com', success: () => { uni.showToast({ title: '邮箱已复制', icon: 'success', duration: 1500 }); }, fail: () => { uni.showToast({ title: '复制失败', icon: 'error', duration: 1500 }); } }); }; // 发送邮件功能 const sendEmail = () => { const email = '2412077392@qq.com'; const subject = encodeURIComponent('投诉建议'); const body = encodeURIComponent('尊敬的客服人员:\n\n您好,我想投诉...'); // 使用Uniapp的API打开邮件客户端 uni.navigateTo({ url: `mailto:${email}?subject=${subject}&body=${body}` }); }; </script> <style lang="scss"> .container { display: flex; flex-direction: column; min-height: 100vh; background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%); padding: 20rpx; } .header-image { width: 100%; border-radius: 20rpx; box-shadow: 0 8rpx 25rpx rgba(0, 0, 0, 0.1); margin-bottom: 40rpx; } .complaint-card { background-color: #fff; border-radius: 25rpx; padding: 40rpx; box-shadow: 0 10rpx 30rpx rgba(0, 0, 0, 0.08); margin-bottom: 40rpx; } .card-title { display: block; text-align: center; font-size: 40rpx; font-weight: bold; color: #2c3e50; margin-bottom: 50rpx; padding-bottom: 25rpx; border-bottom: 4rpx solid #3498db; position: relative; &::after { content: ''; position: absolute; bottom: -4rpx; left: 50%; transform: translateX(-50%); width: 120rpx; height: 6rpx; background: #3498db; border-radius: 3rpx; } } .info-item { display: flex; align-items: center; padding: 30rpx 20rpx; margin-bottom: 30rpx; background-color: #f8fafc; border-radius: 20rpx; border-left: 6rpx solid #3498db; } .icon-container { width: 80rpx; height: 80rpx; border-radius: 50%; background-color: #e3f2fd; display: flex; align-items: center; justify-content: center; margin-right: 25rpx; } .icon { font-size: 40rpx; } .info-content { flex: 1; } .info-label { font-size: 32rpx; color: #7f8c8d; font-weight: 500; display: block; margin-bottom: 10rpx; } .info-value { font-size: 34rpx; color: #2c3e50; display: block; } .action-buttons { display: flex; justify-content: space-between; margin-top: 50rpx; gap: 30rpx; } .action-btn { display: flex; align-items: center; justify-content: center; flex: 1; padding: 25rpx 0; border-radius: 50rpx; font-size: 32rpx; font-weight: 600; box-shadow: 0 4rpx 15rpx rgba(0, 0, 0, 0.1); transition: all 0.3s ease; &:active { transform: scale(0.98); } } .copy-btn { background: linear-gradient(to right, #3498db, #2980b9); color: white; } .mail-btn { background: linear-gradient(to right, #e74c3c, #c0392b); color: white; } .btn-icon { font-size: 40rpx; margin-right: 15rpx; } .btn-text { line-height: 1.5; } .footer { margin-top: auto; text-align: center; padding: 30rpx; } .footer-text { display: block; font-size: 28rpx; color: #7f8c8d; margin-bottom: 15rpx; } /* 响应式调整 */ @media (min-width: 768px) { .container { max-width: 750px; margin: 0 auto; padding: 40rpx; } .complaint-card { padding: 60rpx; } } </style> 我想要去掉复制邮箱和发送邮件按钮以及其相应布局和功能。同时添加点击复制功能点击邮箱或者地址对应位置板块,复制邮箱或地址同事提示已复制邮箱或地址
最新发布
08-09
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值