简体   繁体   中英

How do you copy your set string value to clipboard?

I have a problem and the problem is greater because it's seen as a duplicate by some people here (of: How do I copy to the clipboard in JavaScript? ).

I have

<div class="ce">
   <div class="lotB">9</div>
   <div class="lotB">3</div>
   <div class="lotB">28</div> == $0
  </div>

I want these inner text in form of 9 3 28 , so I set up a string which equals 9 3 28

It's done like that:

var x = document.getElementsByClassName("lotB");
var count = 0;
var text = "";
for (var i = 0; i < x.length && count<3; i++) {
  var nums = x[i].textContent;
  text = text + nums.toString() + " ";
  count++;
}

Then text = "9 3 28"

Now my question, how can I directly copy the value of text to my clipboard such that I can post it somewhere else?

我已经在我的应用程序中使用了它: https : //www.npmjs.com/package/copy-to-clipboard

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM