2016-05-04 123 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