jquery clone combo box not able to function

后端 未结 2 1382
[愿得一人]
[愿得一人] 2021-01-28 18:47

I have the following table where when I press the first button I call a jquery to clone the first row and add a new row.

相关标签:
2条回答
  • 2021-01-28 19:17

    Got it problem is in when you are declaring input use id as addRow not addRow().

     <input type='button' value='Add Row' id='addRow' />
    
    0 讨论(0)
  • 2021-01-28 19:20

    I tried your code in my machine and it worked perfectly. Perhaps your problem lies with the bootstrap combo box. So try refresh or reset the bootstrap combo box.

    I have used a similar plugin and had a similar problem. So I used this and it solved my problem.

    $("#select").selectpicker('refresh');
    

    Also i found a small error in your above pasted code.

    <input type= 'button' value='Add Row' id='addRow' />
    

    instead it was like

    id='addRow()'
    

    So here is the updated code with chosen plugin.

    <script type="text/javascript">
        $(document).ready(function(){
            $("#addRow").click(function(){
                var row = "<tr>"+
                        "<td></td>"+
                        "<td><select class='chosen-select'> <option>1 --</option> <option>2 --</option> <option>3 --</option> <option>4 --</option> <option>5 --</option> <option>6 --</option> <option>7 --</option> <option>8 --</option> </select></td>"+
                        "<td><input  style='font-size:10px;max-width:80%;' class='descInput' type='text' id='desc' name='desc' ></td>"+
                        "</tr>";
                $("#vehReg tbody").append(row);
                $(".chosen-select").chosen();
            });
        });
    </script>
    <body>
        <table id='vehReg'>
            <thead>
                <tr>
                    <th>No.</th> <th>Sel</th> <th>Desc.</th>
                    <th ><input type= 'button' value='Add Row' id='addRow' />
                        <input type='hidden' value='0' id='totalRows' name='totalRows' /></th>
                    </tr>
                </thead>
                <tbody>
    
                </tbody>
            </table>
    </body>
    

    Hope this helps.

    I added the code inside the javascript itself instead of the clone function. In this way it will be easier for you to maintain the count and keep adding the naming conventions to your fields.

    0 讨论(0)
提交回复
热议问题