js手写的弹出框

function cpData() {
    if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) {//区分iPhone设备
       window.getSelection().removeAllRanges();//这段代码必须放在前面否则无效
       var Url2=document.getElementById("copyInput");//要复制文字的节点
       var range = document.createRange();
       // 选中需要复制的节点
       range.selectNode(Url2);
       // 执行选中元素
       window.getSelection().addRange(range);
       // 执行 copy 操作
       document.execCommand('copy');

    }else{
       var Url2=document.getElementById("copyInput");
       Url2.select();
       if (document.execCommand('copy')) {
          document.execCommand('copy');
       }
    }
}
document.execCommand('Copy')

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Vue 3 是一款流行的 JavaScript 框架,用于构建用户界面和单页面应用程序。手写原生出框可以通过 Vue 3 的组件来实现,以下是一个简单的示例: 1. 新建一个名为 "MyAlert" 的 Vue 组件,该组件包含一个 "message" 属性和一个方法 "closeAlert"。 ``` <template> <div class="my-alert" v-show="visible"> <div class="my-alert-mask" @click="closeAlert"></div> <div class="my-alert-content"> <p>{{ message }}</p> <button @click="closeAlert">确定</button> </div> </div> </template> <script> export default { props: { message: { type: String, default: "", }, }, data() { return { visible: true, }; }, methods: { closeAlert() { this.visible = false; }, }, }; </script> <style scoped> .my-alert { position: fixed; top: 0; left: 0; right: 0; bottom: 0; } .my-alert-mask { position: absolute; top: 0; left: 0; right: 0; bottom: 0; background-color: rgba(0, 0, 0, 0.5); } .my-alert-content { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); background-color: #fff; } </style> ``` 2. 在需要出框的地方使用该组件,并传递要显示的消息。 ``` <template> <div> <button @click="showAlert">出框</button> <my-alert :message="alertMsg" v-if="isShowAlert" @closeAlert="isShowAlert=false"></my-alert> </div> </template> <script> import MyAlert from "./MyAlert.vue"; export default { components: { MyAlert, }, data() { return { isShowAlert: false, alertMsg: "", }; }, methods: { showAlert() { this.isShowAlert = true; this.alertMsg = "这是一个出框"; }, }, }; </script> ``` 这样就可以实现一个简单的手写原生出框。相比于使用浏览器的原生出框,自定义的出框更加灵活,并且可以根据需求进行自由扩展。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

十步杀一人_千里不留行

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值