doufu1504 2017-02-06 08:20
浏览 14

在表中添加一个新行,在某些单元格中有一些下拉列表

Just wanted to know if any of you had any code (JQuery, AJAX, etc) to add a new row to a table that has some dropdown lists in some columns... I was able to add a new row by adding some javascript and jquery, but for some reason (it was working before, but suddenly stopped and I cannot recall the last changes I made to be honest) it's not working anymore. First, I made PHP functions to retrieve the contents for the dropdowns from a DB. Then I added the HTML code in a java script function ("Addnewrow()") to add the new rows and include the dropdowns in specific columns. Thing is, rows are only added when I remove the lines in the "Addnewrow()" function that contains the PHP function ("creaLista"). I have tried changing the Jquery versions, removing all bootstrap files and so, but nothing works. I also tried different combinations in those lines of single and double quotes. I also removed the non-essential code, such as the "Render" section for the selectpicker

Here's the javascript section:

function addnewrow()
{

    $('.selectpicker').selectpicker('render');

    var n = ($('.detail tr').length-0)+1;
    var tr = "<tr>" +
                    '<td class="no">' + n + '</td>'+
                    "<td><?php creaLista('mrditemid[]',3,'SPARES_ID','SPARES_BRIEFDESC',$query2, $m);?></td>"+
                    "<td><?php creaLista('mrdunits[]',4,'UNIT_ID','UNIT_DESC',$query2, $m);?></td>"+
                    '<td><input type="text" class="form-control mrdquantity" name="mrdquantity[]"></td>'+
                    '<td><input type="text" class="form-control mrdremarks" name="mrdremarks[]"></td>'+

                    '<td><button class="btnDelete btn btn-danger">-</td>'+
             '</tr>';

    $('.detail').append(tr);
}

I may add that the first row is generated automaticaly in HTML, also calling the same function "crealista" and it works fine. Now, when I click on the button that triggers the "Addrow()" function it simply does nothing, and when I remove the lines containing the "Crealista" function it does work, so it has to do with how the var "tr" is being read, I believe...

Thanks in advance for any insights on this!

  • 写回答

2条回答 默认 最新

  • dps43633 2017-02-06 08:26
    关注
    > function CopyRow(e) {
    >             var r = confirm("Do you want to Copy this record?");
    >             if (r == true) {
    > 
    >                 var $tr = $(e).closest('tr');
    >                 var $clone = $tr.clone();
    >                    var lastRow = $tr.clone();
    > 
    >                 lastRow.find('select').each(function (idx, el) {
    >                     var $el = $(el);
    >                     $el.val($tr.find('select').eq(idx).val())
    >                 });
    >                 $tr.after(lastRow);
    >               
    > 
    >             }
    > 
    >             else {
    >                 return false;
    >             }
    >         }
    

    It will add new row and will also copy the previous row.

    评论

报告相同问题?

悬赏问题

  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上