JS 및 jQuery의 초보자이고 링크를 클릭하면 동적으로 2 행 (오렌지 색과 열이 포함 된 행)을 추가하고 싶습니다. 페이지 하단의 회색 직사각형).테이블에 2 행을 동적으로 추가하는 방법
여기 스크린 샷입니다 :
이 내 HTML 코드입니다 :
<div class="ajout_prest">
<p class="txt_ajout">
<a class="AddResults" href="#">Ajouter une nouvelle prestation</a>
</p>
<p class="plus_ajout">
<a class="AddResults" href="#">+</a>
</p>
</div>
그리고 JS 코드 :
는<script>
$('.AddResults').click(function(){
var rowNumber = 3;
// All the cols
var jourVar = $('<td class="jr_td"><p><input type="text" class="datepicker" /></p><p class="ou">ou</p><p><input type="text" class="datepicker" /></p></td>') ;
var creneauVar = $('<td class="cr_td"><select><option value="h1">10h30</option><option value="h2">11h30</option></select><select class="cr_td_s2"><option value="h3">10h30</option><option value="h4">11h30</option></select></td>') ;
var repassageVar = $('<td class="rp_td"><select><option value="h5" SELECTED>2h00</option><option value="h6">3h00</option></select></td>') ;
var menageVar = $('<td class="mn_td"><select><option value="h7" SELECTED>2h00</option><option value="h8">3h00</option></select></td>') ;
var totalVar = $('<td class="tt_td"><strong>4h.</strong></td>') ;
var pttcVar = $('<td class="pttc_td"><strong>88 €</strong></td>') ;
var corVar = $('<td class="cor_td"><a href="#"><img src="img/ico/corbeille.png" alt="" width="13" height="13" /></a></td>') ;
//Create 2 new rows
var newTitreRow = $('<tr><td class="bar_td" colspan=7><strong>PRESTATION ' + rowNumber + '</strong></td></tr>') ;
var newContentRow = $('<tr>' + jourVar + '' + creneauVar + '' + repassageVar + '' + menageVar + '' + totalVar + '' + pttcVar + '' + corVar + ');
//Append the new row to the body of the #table_prest table
$('#table_prest tbody').append(newTitreRow);
$('#table_prest tbody').append(newContentRow);
//Iterate row number
rowNumber++;
});
</script>
그러나 물론 아무 일도 일어나지 않습니다. 이 문제에 대해 알고 있습니까?
당신을 :) 감사
감사합니다. 이제 RowNumber 변수에서 작동하고 첫 번째 행 (주황색 행)이 추가됩니다. 두 번째 "newContentRow"가 표시되지 않습니다. – Copernic
다른 답변에서 언급했듯이 jQuery 객체를 문자열로 결합 할 수 없습니다. newContentRow의 개별 셀에 대한 jQuery 객체를 제거하고 문자열을 사용하거나 newContentRow에 셀을 추가 할 때 대신 .append 메서드를 사용하십시오. http://jsfiddle.net/ioncache/6kkfr/3/ – ioncache
고마워 지금은 작동합니다 :) – Copernic