JS实现文本全选并复制

项目需要,自己用execCommand()方法写了一个,目前在IE,chrome,fireFox 都正常运行;

话不多说,直接代码:

HTML部分
<input  class="addresNm" type="text" value="这里是等待被复制的东东" />
<input class="copyBtn" type="button" value="点击复制"/>
Js部分
<script>
$('.copyBtn').click(function () {
        var Input = $('.addresNm');
         Input.focus()
         Input.select()
         try{
              document.execCommand('copy');
         }catch(e){}                                                     
                                                           
 })
</script>    

代码大概意思,具体需要实际需要而写;此用于个人记录总结。

什么叫见过大世面?就是能享受最好的,能承受最坏的。
原文地址:https://www.cnblogs.com/jingaier/p/7070640.html