jQuery点击按钮复制文本内容

该段代码展示了一个HTML结构,包含一个树形选择器(tree-select)和一个复制按钮。当点击复制按钮时,JavaScript函数被触发,用于选取并复制树形选择器中的文本值到剪贴板。代码利用了document.getElementById,document.execCommand(copy)等方法来实现复制功能。
摘要由CSDN通过智能技术生成

点击按钮复制文本类容

<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>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值