美文网首页
jquery复制链接(复制Url链接)

jquery复制链接(复制Url链接)

作者: leleo | 来源:发表于2019-11-25 11:26 被阅读0次
$('点击对象').on('click',function(){
    copyUrl($(this));
  });
  function copyUrl (obj){
    if($('#urlText').length == 0){
      // 创建input
      obj.after('<input id="urlText" style="position:fixed;top:-200%;left:-200%;" type="text" value=' + window.location.href + '>');
    }
    $('#urlText').select(); //选择对象
    document.execCommand("Copy"); //执行浏览器复制命令
  }

相关文章

网友评论

      本文标题:jquery复制链接(复制Url链接)

      本文链接:https://www.haomeiwen.com/subject/zwpdwctx.html