2016-11-08 63 views
-1

我在其他线程中查找了相同的问题,但找不到解决方案。
我想克隆一个表行,并通过更改输入字段的索引将它追加到同一个表中,并且还删除了添加字形图标,并用具有onClick函数的新字形图标替换它,并且当我尝试删除单击字形图标上的行我得到此(未捕获的SyntaxError:意外的令牌})错误。我一遍又一遍地检查了我的代码,但找不到解决方案。
这里是我的代码在尝试删除表格行时动态获取未捕获的SyntaxError:Unexpected token}

$(document).ready(function(){ 


     var glyphRemove=""; 

      glyphRemove="<span class='glyphicon glyphicon-minus glyph_size' id='remove' onClick='$(this).closest('tr').remove()' aria-hidden='true'></span>"; 
       $("#add").click(function() {    

        var clone= $("#cloneObject").clone();      
        clone.removeClass('hide');    
        clone.prop('disabled',false); 
        clone.find('#add').remove(); 
        clone.find('#glyph').append(glyphRemove);      
        clone.appendTo("#shiftsTable");  



        }); 
    }); 

当我改变了onClick功能onClick=$this.parent().parent().remove()怎么过,这工作完全正常,并删除含有字形图标的td部分。
我哪里错了。

+0

你有额外的'}''线clone.appendTo( “#shiftsTable”)之后;' – Satpal

+0

的{之后clone.appentTo( “#shiftsTable”) ;是多余的。 –

+0

你也会遇到'onClick ='$(this).closest('tr')。remove()''的问题,仔细看看这些引号。 –

回答

1

这里:

glyphRemove="<span class='glyphicon glyphicon-minus glyph_size' id='remove' onClick='$(this).closest('tr').remove()' aria-hidden='true'></span>"; 
       $("#add").click(function() {    

        var clone= $("#cloneObject").clone();      
        clone.removeClass('hide');    
        clone.prop('disabled',false); 
        clone.find('#add').remove(); 
        clone.find('#glyph').append(glyphRemove);      
        clone.appendTo("#shiftsTable");  
       } 
       ^


        }); 

删除它。

+0

}不是额外的我在追加之前有一些逻辑,我使用这个逻辑,但是我从我的问题中删除了不需要的代码,这是错误的。我仍然有同样的问题。 –

0

您的代码应该是这样的:

$(document).ready(function(){ 
    var glyphRemove=""; 
    glyphRemove="<span class='glyphicon glyphicon-minus glyph_size' id='remove' onClick='$(this).closest('tr').remove()' aria-hidden='true'></span>"; 
    $("#add").click(function() {    
     var clone= $("#cloneObject").clone();      
     clone.removeClass('hide');    
     clone.prop('disabled',false); 
     clone.find('#add').remove(); 
     clone.find('#glyph').append(glyphRemove);      
     clone.appendTo("#shiftsTable");  
    }); 
}); 
+0

这里有什么不同? –

相关问题