refers to a similar question raised by a big shot earlier: https://codeshelper.com/q/10.
found that if there are multiple elements, only the text in the last element will be retained.
my idea is to first select the text to be copied one by one, and finally copy it together, but without success. Google browser for
.
the failed code is as follows:
for (let i = 0; I < $("input:checked"). Parent (). Next (). Children (). Length; iPP) {
var text = $("input:checked"). Parent (). Next (). Children () [I]
var selection = window.getSelection ()
var range = document.createRange ()
range.selectNodeContents (text)
selection.removeAllRanges () / / do not understand the meaning here, if you delete this sentence, it will not be copied directly. But if you don"t delete it, it feels like it will be emptied every time, so you can"t copy multiple lines.
selection.addRange (range)
}
document.execCommand ("Copy","false",null)
requirements: copy the text of all eligible elements to the clipboard and keep the formatting (line wrapping)
if there are other ways to achieve this requirement, please let me know
Thank you!