2014-02-20 40 views
4

我有一个jbuery库“Tablesorter”的表建设,我想在这个表中添加一行,当我点击一个按钮,但是当我添加该行时,这不需要CSS的tablesorter的..所以我不能选择他或CSS的“奇”,“偶”不工作..用tablesorter在表中添加一行jquery

$("#ajouterCodePiece").click(function(){ 
    $('#tablesorter-demo-gauche tr:last').after('<tr'><td>'+$('#codepiece option:selected').text()+'</td><td>'+$('#mode option:selected').text()+'</td></tr>'); 
}); 

如何为的tablesorter的新增CSS和jQuery在我的新行做..谢谢

+2

你的'''不匹配的开始! '。'('​​'....' –

+0

像这样的'$('#codepiece option:selected')'的任何单引号需要通过反斜线转义或用双引号替换**“”* * – dreamweiver

+0

好吧,但我的行被添加在表中,但没有库的tablesorter的CSS ..例如..如果我添加行==>它被添加到表,但我不能选择他,而不是css的“奇怪”或“even”等等...... – user1814879

回答

2

Tablesorter将所有表内容存储在缓存中,因此为了告诉tablesorter某些内容已经更改,您需要触发更新:

$('table').trigger('update'); 

这本updated demo

$("#ajouterCodePiece").click(function() { 
    $('#tablesorter-demo-gauche tr:last').after('<tr><td>' + $('#codepiece option:selected').text() + '</td><td>' + $('#mode option:selected').text() + '</td></tr>'); 
    $('#tablesorter-demo-gauche').trigger('update'); 
}); 
+0

非常感谢。行“奇数”“偶数”的工作,但我不能选择新的行..你可以在这里看到它...如果你点击第1或第2行它确定http://jsfiddle.net/t988C/ 35/ – user1814879

+0

将突出显示功能更改为绑定到[委托事件](http://api.jquery.com/on/#direct-and-delegated-events),如下所示:'$(“#tablesorter-demo-gauche “).on(”click“,”tr“,function(){});' - 这是[更新演示](http://jsfiddle.net/Mottie/t988C/40/) – Mottie

+0

。 谢谢 – user1814879