(-) button doesn't work and if clicked (+) button,then add double or more rows,but i want if click (+) button,it will be add one row.how to modify my code. thank youphp code
<td>
<span>
<input type="text" name="document_sign_user_order" style="width:20px;"/><select name="fk_dept_seq">
<option>--------</option>
<!--{@ depts }-->
<option value="{.dept_seq}">{=_(.dept_name)}</option>
<!--{/}-->
</select><select name="fk_position_seq">
<option>--------</option>
<!--{@ positions }-->
<option value="{.position_seq}">{=_(.position_name)}</option>
<!--{/}-->
</select><select name="fk_user_seq">
<option></option>
<!--{@ users }-->
<option value="{.user_seq}">{=_(.user_name)} [{=_(.dept_name)}]</option>
<!--{/}-->
</select>
<button class="btn_del_opt">-</button>
</span>
<button class="btn_add_opt">+</button>
</td>jquery code(function($){// var btn_del = $('button.btn_del_opt');
// var btn_add = $('button.btn_add_opt');function del_opt(obj)
{
if($(obj).parent().parent().next().children('td').children('span').length == 1)
{
return alert('삭제하실수 없습니다.');
}
$(obj).parent().parent().next().last().remove();
cont_btn();
}function add_opt(obj)
{
console.log($(obj));
$(obj).parent().parent().after($(obj).closest('tr').clone());
$(obj).parent().parent().next().children('td').children('span').children('input').val('');
cont_btn();
}function cont_btn()
{
$('button.btn_del_opt').map(function(k,v){
$(v).click(function(){
del_opt(this);
});
});
$('button.btn_add_opt').map(function(k,v){
$(v).click(function(){
add_opt(this);
});
});
}cont_btn();})(jQuery);

解决方案 »

  1.   

    Oh, great this problem is about the js of jQuery, let me check.
    But your codes is so jumbled, it is difficult to read for someone.Could you talk details about your function of code that is how to work , 
    or using for what, let me know your thinking, then help you exactly. 
      

  2.   

    I advise you to use the append() function add rows of table, personally. 
      

  3.   

    function add_opt(obj)
    {
    console.log($(obj));
    // Here, where is your code that adds more rows ?
    // I have saw you add one row.

    $(obj).parent().parent().after($(obj).closest('tr').clone());
    $(obj).parent().parent().next().children('td').children('span').children('input').val('');

    cont_btn();
    }