用javascript把内容复制到剪贴板 复制两个个html标签之间内容(包括html) <html><head><script>function doIt() { var x=document.getElementById(\'dajm\'); document.form.copyArea.value=x.innerHTML; alert(document.form.copyArea.value); y = document.form.copyArea.createTextRange(); y.select(); y.execCommand("Copy");}</script></head><body onload="doIt()"><p>Outside Div</p><div id="dajm"> <table border="1" width="100%"> <tr> <td width="50%">Inside Div</td> <td width="50%"> </td> </tr> <tr> <td width="50%"> </td> <td width="50%"> </td> </tr> </table></div><form name="form"> <input type="hidden" name="copyArea" value></form><p>Outside Div</p></body></html> 去除空行和空格的代码 无空行<html><head><script>function doIt() { var x=document.getElementById(\'dajm\'); document.form.copyArea.value=x.innerHTML; a = document.form.copyArea.value; a = a.replace(/(\ )+/g,""); a = a.replace(/<[^<>]+>/g,""); a = a.replace(/\n[\s| ]*\r/g,""); alert(a); y = document.form.copyArea.createTextRange(); y.select(); y.execCommand("Copy");}</script></head><body onload="doIt()"><p>Outside Div</p><div id="dajm"> <table border="1" width="100%"> <tr> <td width="30%">Inside Div</td> <td width="40%"> </td> <td width="30%"> </td> </tr> <tr> <td width="30%"> </td> <td width="40%">123</td> <td width="30%">44444</td> </tr> </table></div><form name="form"> <input type="hidden" name="copyArea" value></form><p>Outside Div</p></body></html> posted on 2006-07-04 21:00 Vinson 阅读(919) 评论(0) 编辑 收藏 举报 相关文章: JS复制内容到剪贴板 2021-04-18 ALV复制内容到剪贴板 2021-06-05 js复制内容到剪贴板 2021-12-13 js将内容复制到剪贴板 2021-12-03 js 将内容复制到剪贴板 2021-12-03 JavaScript复制内容到剪贴板的两种常用方法 2021-09-28 JQuery实现内容复制到剪贴板 2021-12-19 vim复制内容到系统剪贴板 2021-12-12