首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

insertrow后怎么用jquery复制行

2012-09-10 
insertrow后如何用jquery复制行script typetext/JavaScript srcjquery-1.1.3.pack.js/script!-

insertrow后如何用jquery复制行
<script type="text/JavaScript" src="jquery-1.1.3.pack.js"></script><!--这里引入jquery的文件-->
<script type="text/javascript">

  function add()
  {
  var tb=document.getElementById("myTable2");
  var myRow = tb.insertRow();

  myRow.insertCell().innerHTML="3243423";
  }
  /*------------*/
var key = window.event ? e.keyCode : e.which;
  $(document).ready(function () {
   
  $("#myTable2 tr").click(function () {
  if (event.keyCode == 45) 
  {  
  $(this).clone(true).insertAfter(this);
  }  
  });
  });
</script>
<table border="1" width="200" id="myTable2">

</table>
<input type="button" onClick="add()" value="click me">

实现以上 $(this).clone(true).insertAfter(this);敲击“+”号键盘键,就可以复制加载。

[解决办法]

JScript code
<script type="text/javascript">  $(function () {        $("#myTable2 tr ").bind({            "keydown":function(e){                var Key=e.keyCode||e.which||e.charCode;                if (Key == 107 || Key == 187)//187是右边数字小键盘上的,107是左边退格键旁边的                  {                       $(this).clone(true).insertAfter(this);                }              },            "click":function(e){                $(this).clone(true).insertAfter(this);            }        })  });</script><table border="1" width="200" style="width:200px;height:20px;" id="myTable2"><tbody><tr tabindex="0"><td>原始内容</td></tr></tbody></table> 

热点排行