简体   繁体   中英

How to copy a whole section (input texts, dropdown value,) all togther in one line with javascript?

I want to create a program where my colleagues can input some number then issue name then product name, quantity, resolution given and can copy all these things to the clipboard in single line.

Ex:. 1234 // Damaged // Dell laptop // Q-1 // Repairing slot given //

I want this line to be copied with a button clicked and the values can be changes by the user.

This is code, but the problem is I have to give different ids to the elements and also it is copied seprately.

function copyToClipBoard() {

    var content = document.getElementById('textArea');
    
    content.select();
    document.execCommand('copy');

    alert("Copied!");
}

You can get the value out of the textarea element using element.value and then call the writeText() function on navigator.clipboard passing it the value of the element.

example:

  function copyToClipBoard() {
    var element = document.getElementById('textArea');
    var content = element.value

    navigator.clipboard.writeText(content);
  }

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