首页 新闻 会员 周边

Jquery操作HTML元素

0
悬赏园豆:5 [已解决问题] 解决于 2012-09-17 13:34

   <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");
            });

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

       });

ruonanxiao的主页 ruonanxiao | 初学一级 | 园豆:6
提问于:2012-07-12 15:17
< >
分享
最佳答案
0
$(function(){
    $("#btnAdd").click(function(){
        $("#trProduction").after($($("#trProduction")).clone());
    });
});
收获园豆:5
artwl | 专家六级 |园豆:16736 | 2012-07-12 15:47
其他回答(3)
0

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

code先生-null | 园豆:307 (菜鸟二级) | 2012-07-12 16:01
0

appendTo(content) 把所有匹配的元素追加到另一个指定的元素元素集合中。

 $("<input type='text' name='ddd' id='ddd' value='Hello, Nowamagic' ><br>").appendTo("#trProduction")

appendTo("#trProduction")这样写是不是有问题

普通用户 | 园豆:54 (初学一级) | 2012-07-12 17:50
0

给上一个tr加个id然后将这个带id的tr中的内容通过appendTo加载到你想要显示的位置。

jerry-Tom | 园豆:4077 (老鸟四级) | 2012-07-13 10:13
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册