Jquery操作HTML元素

   <tr id="trProduction">
                    <td >
                        <table style="border: dashed 2px red; width: 100%;height:100%;" align="left">
                            <tr>
                                <td>
                                    年:<span style="color: red">*</span>
                                </td>
                                <td>
                                    <input id="txtMonth" type="text" value="2012" style="width: 200px" />
                                </td>
                            </tr>
                            <tr style="display: inline">
                                <td>
                                    数量:<span style="color: red">*</span>
                                </td>
                                <td>
                                    <input type="text" value="14520,00" style="width: 140px;" />
                                    <select style="width: 60px">
                                        <option>Tonne</option>
                                    </select>
                                </td>
                            </tr>
                            <tr style="display: inline">
                                <td>
                                    值:
                                </td>
                                <td>
                                    <input type="text" value="12580,00" style="width: 140px;" />
                                    <select style="width: 60px">
                                        <option>USD</option>
                                    </select>
                                </td>
                            </tr>
                        </table>
                    </td>
                    <td><input id="btnAdd" type="button" value="增加" />      
                     </td>
                </tr> 

 

我想在点击btnAdd 的时候,自动在上面的tr id=trProduction 这行后面 继续添加上面的一个tr,重复内容.请教实现方法

   $(document).ready(function() {
            $("input:button[id=btnAdd]").click(function() {
                $("<input type='text' name='ddd' id='ddd' value='Hello, Nowamagic' ><br>").appendTo("#trProduction");
            });

........................................

       });

白猪掌柜的
浏览 416回答 4
4回答

慕勒3428872

$(function(){ $("#btnAdd").click(function(){ $("#trProduction").after($($("#trProduction")).clone()); }); });

牛魔王的故事

 $("#btnAdd").click(function () {                $(this).parents("table").append($($(this).parent().parent()).clone());            });

青春有我

appendTo(content) 把所有匹配的元素追加到另一个指定的元素元素集合中。  $("<input type='text' name='ddd' id='ddd' value='Hello, Nowamagic' ><br>").appendTo("#trProduction") appendTo("#trProduction")这样写是不是有问题

侃侃无极

给上一个tr加个id然后将这个带id的tr中的内容通过appendTo加载到你想要显示的位置。
打开App,查看更多内容
随时随地看视频慕课网APP