<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);敲击“+”号键盘键,就可以复制加载。

解决方案 »

  1.   

    <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>为了兼容浏览器,给tr增加了 tabindex="0" 以使其在FF,Chrome上可以获得焦点
    我看你原代码绑的是click事件,不知道你是需要还是搞错了,如果不需要,你可从上面代码中移除对click事件的绑定
      

  2.   

    楼上的似乎不行。
      <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";
      } $(function () {
            $("#myTable2 tr ").bind({
                "keydown":function(e){
                    var Key=e.keyCode||e.which||e.charCode;
                    if (Key == 49 || 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><input type="button" onClick="add()" value="click me">
    我要先实现insertsell(),然后复制重载我选定的行。其实也不限制与js或者jquery。似乎楼上的快捷键有误?不知我说错了吗?
      

  3.   


    你看清楚,我给你的答案里,并没有包含你自己原来的add函数,而是给了一个默认的行,然后直接鼠标点击那行后,按两个+号即可实现复制像这种需要示例的,我一般都会在IE6,7,8,FF,Chrome下均已经测试无误我才会贴出来
      

  4.   

    你如果需要单独的新增一行,那么,你就要做如下修改:
    1:add()修改如下:
    function add(){
        $("#myTable2").append("<tr tabindex='0'><td>3243423</td></tr>")
    }
    2:行的绑定事件修改如下:即将 .bind()改为.live()。.bind()只能绑定现有元素,但你这里一开始是不存在tr的,因此事件将失效。更改为.live()以后,将可以使所有后添加进来的元素也能绑定自定义事件
     $(function () {
            $("#myTable2 tr ").live({
                "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);
                }
            })
      });
      

  5.   

    加载以下jquery库试试<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>你原来的:
    <script type="text/JavaScript" src="jquery-1.1.3.pack.js"></script>这是嘛版本?我玩jquery是从1.8版本开始的,比较晚,我都没见过这个