javascript复制与粘贴字符串操作

来源:互联网 发布:js json格式化输出 编辑:程序博客网 时间:2024/06/05 14:38

 

 

 

 

 

 

 

C#?CopyCode image复制代码
 public partial class Employee {    public void DoWork()      {  } } public partial class Employee {      public void GoToLunch()      {      } }   

 


<html>
<head>
</head>
<body>
<script>
function CopyCode(key)
{
 var trElements = document.all.tags("tr");//获取tr元素
 var i;
 for(i = 0; i < trElements.length; ++i)
 {
  if(key.parentElement.parentElement.parentElement == trElements[i].parentElement)//是同一个tbody时,就将innerText放到剪切版
  {
   window.clipboardData.setData("Text", trElements[i].innerText);
  }
 }
}
function ParseCode()
{
 document.all("txt").value = window.clipboardData.getData("Text");//粘贴

}
</script>
<table width="100%" cellspacing="0" cellpadding="0" name="q" id="q">
<tbody id="w">
 <tr id="c">
  <th id="d">C#?</th>
  <th id="e">
   <span id="a" class="copyCode" onclick="CopyCode(this)" tabindex="0">
    <img class="copyCodeImage" name="ccImage" align="absmiddle" alt="CopyCode image" src=""></img>复制代码
   </span>
  </th>
 </tr>
 <tr id="f">
  <td colspan="2" id="g">
   <pre>
 public partial class Employee
 {
    public void DoWork()
      {
  }
 }

 public partial class Employee
 {
      public void GoToLunch()
      {
      }
 }
   </pre>
  </td>
 </tr>
</tbody>
<tbody>
 <tr>
  <textarea rows="10" cols="50" id="txt"></textarea><input onClick="javascript:ParseCode();" type="button" value="粘帖" id="cmdParse">
 </tr>
</tbody>
</table>
</body>
</html>
来自:javascript复制与粘贴字符串操作

来自:http://www.cnblogs.com/lei1217/archive/2008/01/21/947220.html

原创粉丝点击