首页 前端知识 jQuery点击按钮复制文本内容

jQuery点击按钮复制文本内容

2024-06-04 10:06:26 前端知识 前端哥 294 416 我要收藏

点击按钮复制文本类容

<tree-select id="resDepartId_form"  name="resDepartId" class='col-input noSolbarTree'ng-model="formDataMain.resDepartId"  ztree-data="resOrgObjData"chk-style="radio" correlate="false" ng-readonly="operation == 'operDetail'" select-key="longName" ng-required='true'></tree-select>
<div class="btnCopy" id="suoshubumen" title="复制">
	<i class="fa fa-copy"></i>
</div>
<script type="text/javascript">
                $(document).ready(function(){
                  $("#btnCopy").click(function(){
                      //var valId = document.getElementById("resDepartId_form");
                      //var textCont = valId.getAttribute("value")
                      //var textValee = valId.select();
                      //console.log('文本信息:'+textValee)

                      //var text = document.getElementById("resDepartId_form");
                      //var textCont = text.getAttribute("value");

                      //console.log('valIdvalIdvalIdvalId:'+textCont)

                      //$('#resDepartId_form').val(textCont).select();
                      //document.execCommand('Copy');
                      // $.copy(textCont);


                      var text = document.getElementById("resDepartId_form");
                      var textCont = text.getAttribute("value");
                      console.log('valIdvalIdvalIdvalId:'+textCont)
                      var $temp = $('<input>');
                      $('body').append($temp);
                      $temp.val(textCont).select();
                      document.execCommand('copy');
                      $temp.remove();
                      alert('复制成功1!');

                  });

                });
                </script>
转载请注明出处或者链接地址:https://www.qianduange.cn//article/10790.html
标签
评论
发布的文章
大家推荐的文章
会员中心 联系我 留言建议 回顶部
复制成功!