2014-11-11 5 views
0

복제 된 값으로 td 값을 대체 할 작은 js 스크립트를 만들려고합니다.jQuery는 복제본으로 div를 대체합니다.

나는 더 명확하게 바이올린을 만들었습니다.

테이블의 자세히 버튼을 클릭 한 다음 복제 된 div '123'을 사용하여 더보기를 교체하려고합니다. 그리고 나는 그것이 마지막 tr의 마지막 td가되기를 원하지만, 나는 나중에 그것을 살펴볼 것입니다.

Fiddle Example

jQuery(document).ready(function($) { 

    $('table').each(function(){ 
    var $table = $(this); 
    var n = $(this).find("tr:nth-child(4) td:visible").length; 
    var c = $(this).find('tr:nth-child(3)').last().find('td:last').clone(); 
    $(this).find('tr:nth-child(3)').last().find('td:last').html(
     "<a href='javascript:void(0)' class='more-countries-big'>More</a>" 
    ); 
    var x = $("<a href='javascript:void(0)' class='more-countries-big'>More</a>"); 
    x.on('click', function(){ 
     $table.find('tr:nth-child(3)').last().find('td:last').html(c.html()); 
    }); 
    }); 
    $("table").each(function(){ 
    var $tr = $(this).find('tr'); 
    $tr.hide(); 
    $tr.eq(0).show(); 
    $tr.eq(1).show(); 
    $tr.eq(2).show(); 
    }); 

    $('a.more-countries-big').on('click',function(){ 
     var txt = $(".open-continents").is(':visible') ? 'More' : 'Less'; 
     $(this).parents('table').find('tbody tr').toggleClass('open-continents'); 
     $(this).parents('table').find('a.more-countries-big').text(txt); 
    }); 

}); 

+0

주어진 테이블에서 모든 숫자가 동일합니까? 그렇지 않다면 복제 된 가치가 무엇인지 어떻게 알 수 있습니까? – FirstLegion

+0

당신은 어디서나'n'을 사용하지 않았고 변수에'$'을 사용하지 않았습니다. 어쨌든, 당신의 질문은 나를 위해 너무 깨끗하지 않습니다. 몇 번이나 복제하고 싶은가요? – vaso123

+0

나는 수수께끼를 바꾸었다. http://jsfiddle.net/3yfbb3kw/ ... 123l로 바꾸려면 첫 번째 테이블에서 More를 클릭하면된다. 두 번째 테이블의 More 버튼을 클릭하면 Less with 123z를 바꿉니다. 이것이 더 명확 해지기를 바랍니다. 고맙습니다. –

답변

0

귀하의 솔루션은 여기에 감사 : 당신은 그런 식으로 사용할 수 있습니다 : 당신이 더 많은 열이 다른 링크 존경받는 이벤트를 사용하여 추가 할 경우

$('a.more-countries-big').on('click',function(){ 
     if($(this).hasClass('less')) { 
      $(this).removeClass("less"); 
      $(this).text("More"); 
      $(this).parents("table").find("tr:last").remove(); 
     } else { 
      var tds = $(this).parents("table").find("tr:last").html(); 
      $(this).parents("table").append("<tr>"+tds+"</tr>"); 
      $(this).addClass("less"); 
      $(this).text("Less"); 
     } 
    }) 

.

관련 문제