2016-05-04 49 views
-2

當我點擊添加字符串BTN>我克隆第一TR蒙山輸入表並添加在該表中,我需要在佔位符複製element.How確定最後的佔位符添加+1號。副本之前,並添加新的複製佔位符/ 這個HTML表格如何添加佔位符順序添加號碼?

<div class="matrix_a_cover"> 
    <table class="matrix_a brackets" id="matrix_a"> 

      <tr> 
      <td class="str_inp"> 
      <input type="text" placeholder="a1,1"> 
      </td> 
      <td class="str_inp"> 
      <input type="text" placeholder="a1,2"> 
      </td> 
     </tr> 

      <tr> 
      <td class="str_inp"> 
      <input type="text" placeholder="a2,1"> 
      </td> 
      <td class="str_inp"> 
      <input type="text" placeholder="a2,2"> 
      </td> 
     </tr> 

     <tr> 
      <td class="str_inp"> 
      <input type="text" placeholder="a3,1"> 
      </td> 
      <td class="str_inp"> 
      <input type="text" placeholder="a3,2"> 
      </td> 
     </tr> 

     <tr> 
      <td class="str_inp"> 
      <input type="text" placeholder="a4,1"> 
      </td> 
      <td class="str_inp"> 
      <input type="text" placeholder="a4,2"> 
      </td> 
     </tr> 


     </table> 
    </div> 

這段代碼複製元素

$('.add_str').click(function(){ 
    if ($("#check_mtrx_a").prop("checked")){ 
    $('.matrix_a tr:first').clone().appendTo('.matrix_a'); 
    }else if($("#check_mtrx_b").prop("checked")) { 
    $('.matrix_b tr:first').clone().appendTo('.matrix_b'); 
    } 
}); 

,如果需要例子是如何工作的這一切鏈接serjo96.github.io/matrix

+0

這裏有什麼問題? – Justinas

回答

-1

觸發以下功能時您更新表格

function placeHold() { 
$('tr').each(function(i,v){//loop each row 
    $(v).find('td').each(function(x,d){//loop each colon in that row 
    $(d).find('input').attr('placeholder','a'+i+','+x);//change the input placeholder 
    }); 
}); 

注意:這將從a0,0開始

+0

如何從1.1開始計數? – Drop

+0

它很難做到這一點,你需要複雜的數學'$(d).find( '輸入')。ATTR( '佔位', '一' +(I + 1)+ '' +(X + 1)) ;' – madalinivascu

+0

oh.thank you very much! – Drop