thank
var copy1 = document.getElementById('copy1'); var copy2 = document.getElementById('copy2'); var textBox = document.getElementById('textBox'); copy1.onclick = function() { copyText(textBox); } copy2.onclick = function() { copyText('电话号码:' + textBox.innerHTML); } /**复制文本 */ function copyText(node) { if (!node) { return; } var result; //Adding to copy the contents of the temporary element textarea var tempTextarea = document.createElement ( 'textarea' ); document.body.appendChild (tempTextarea); IF ( typeof (Node) == 'Object' ) { // copy the contents of the node / / whether the form iF (node.value) { tempTextarea.value = node.value; } the else { tempTextarea.value = node.innerHTML; } } the else { // directly copy the text tempTextarea.value = Node; } //Judgment means var U = navigator.userAgent; IF (u.match (/ (the iPhone | iPod | the iPad);? / I)) { // iOS // remove the selected element window.getSelection () removeAllRanges (). ; // create a Range object var the Range = document.createRange (); // select range.selectNode (tempTextarea); // execute the selected element window.getSelection () AddRange (the Range);. // copy result = document.execCommand ( 'Copy' ); // remove the selected element window.getSelection () removeAllRanges ().; } The else { // check tempTextarea.select (); // copy Result = document.execCommand ( 'the Copy' ); } // remove temporary text field document.body.removeChild (tempTextarea); IF (Result) { Alert ( 'copy success' , { removeTime: 1000 }) } the else { Alert ( 'replication failure' , { removeTime: 1000 }) } return Result; }
Andrews test, no test ios