用live绑定事件,如果是高版本jQuery,使用on绑定
比如,$("#divtest]").click(function () {})
写成 $(document).on('click', '#divtest', function (){}) 试试

解决方案 »

  1.   

    每次添加就在tr添加一个index属性,当添加时读取这个属性值
      

  2.   

    不写成代码高亮格式,看得蛋疼。一般来说,动态添加的html节点都要用on 或live事件绑定
      

  3.   

    你好!td的click事件中需要传入this对象,进而修改当前td的innerHTML。使用on绑定怎么样传入这个参数合适呢?
      

  4.   

    你好!绑定事件的函数代码如下function showcolDebite(_this){
    var tx="test";
    try {
    if(_this.innerHTML.length<50){
            _this.innerHTML="<textarea cols='33' >"+tx+"</textarea>";//此处赋值抛出异常unknown runtime error
                }
    }catch(e){
    alert(e.message); 
    alert(e.description); 
    alert(e.number); 
    alert(e.name);      
    }
    }
      

  5.   

    你tr append 進 tr裡  rowindex當然不會增加
    應該改成 before() 或是 after()
      

  6.   

    大家好//增加行函数
    function addsubject(_this){
    var trindex=_this.parentNode.parentNode.rowIndex-1;
      var trHTML = ['<tr class="entry_item">',
                    '<td class="operatesubject" style="border-top-width: 0px; border-right: #ff0000 0px solid; border-left: #ff0000 0px solid;"><input type="button" value="增加"  onclick="addsubject(this)"  style="width: 30px;height: 25px"/><BR/><input type="button" value="删除"  onclick="delsubject(this)"  style="width: 30px;height: 25px"/></td>',
                    '<td class="col_summary" onclick="showSummary(this)"></td>',
                    '<td class="col_subject" onclick="showSubject(this)">',
                    '<div>',
                    '<div style="position:relative;left:0;top:0" class="sp_subject">',
                    '<textarea cols="33" rows="3" onblur="subjectshowdiv(this)" class="tex_subject"></textarea>',
                    '</div>',
                    '<div style="position:relative;left:0;top:0" class="initsubject"></div>',
                    '</div>',
                    '</td>',
                    '<td class="col_debite" id="col_debite">123</td>',
                    '<td class="col_credit" onclick="showcolCredit(this)"></td>',
                    '</tr>'].join('');
         $("#voucher tr:eq("+trindex+")").append(trHTML); 
         refreshaut();//添加行后重新刷新科目自动补全插件bigAutocomplete
         

    //点击td后修改td的innerHTML这样写赋值时还是出现unknown runtime error
    $(document).on('click', '#col_debite', function (e){
    var _this=this;
    var tx="";
    if(_this.innerHTML.length>2){
           tx=_this.innerHTML.substring(0,_this.innerHTML.length-2)+"."+_this.innerHTML.substring(_this.innerHTML.length-2,_this.innerHTML.length)
    }
    try {
    if(_this.innerHTML.length<50){
            _this.innerHTML="<textarea cols='33' style='width:218px;height:55px;font-size: 20px;font-family: '宋体';' onblur='showmoneydiv(this)' onkeyup='suDebite(this)'>"+tx+"</textarea>";
    }
    }catch(e){
    alert(e.message); 
    alert(e.description); 
    alert(e.number); 
    alert(e.name);      
    }
    _this.childNodes[0].focus();
    _this.childNodes[0].select();
    }) 
      

  7.   

    你好,改用$("#voucher tr:eq("+trindex+")").before(trHTML); 可以正常按顺序添加了,谢谢。