2014-02-20 2 views
4

jquery 라이브러리 "Tablesorter"가있는 테이블 작성 기능이 있고 버튼을 클릭 할 때이 테이블에 행을 추가하고 싶지만 행을 추가 할 때 CSS를 사용하지 않습니다. tablesorter에의 ... 그래서 난 그를 선택하지 못할, 또는 "홀수"는 CSS는 "도"작동하지 않습니다 .. 내 새 행에 tablesorter에의 추가 CSS 및 JQuery와 위해 할 수있는 방법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>'); 
}); 

를 .. 감사

+2

! '.after (''.... –

+0

'$ ('# codepiece option : selected')'와 같은 작은 따옴표는 백 슬래시로 이스케이프하거나 큰 따옴표로 바꿔야합니다. ** ""* * – dreamweiver

+0

좋아,하지만 내 행은 테이블에 추가되지만 라이브러리 tablesorter의 CSS는 없습니다 .. 예를 들어 .. 행을 추가하면 ==> 테이블에 추가되지만 "odd"또는 css가 아닌 그를 선택했습니다. "even"등등 ... – user1814879

답변

2

Tablesorter는 모든 테이블 내용을 캐시에 저장하므로 tablesorter에게 변경된 사항을 알리려면 업데이트를 트리거해야합니다.

6,

$('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

그건 worrk weel입니다. . 고맙습니다 – user1814879