javascript复制与粘贴字符串操作

 

 

 

 

 

 

<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>  

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" οnclick="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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值