首页 新闻 赞助 找找看

Jquery clone(true)和clone()的問題?

0
悬赏园豆:10 [已关闭问题]

<table><tr style="height: 20px" id="tr_id" name="moban">
                   <td><input type="text" id="xuhao_id" style="display:none" />001</td>
                    <td><input type="text" id="bookno_txt"  /></td>
                    <td> <input type="text" id="customer_txt"  /></td>
                    <td><input type="text" id="modelno_txt"  /></td>
                    <td> <input type="text" id="model_txt"  /></td>
                    <td style="border: 0px">
                        <strong onclick="AddTR(this);" style="cursor: hand">
                            <img src="../Images/add.gif" /></strong> <strong onclick="RemoveTR(this)" style="cursor: hand">
                                <img src="../Images/del.gif" /></strong>
                    </td>
                </tr></table>

function AddTR(ths){
   var cloneTr = $(ths).parents('tr:first').clone(true);  
   //alert(cloneTr.html());
   //alert($(ths).parents('tr:first').find("select option:selected").val());
   cloneTr.insertBefore($(ths).parents('table:first').find('tr:last'));
}

當我Clone成功后,再點Clone后的TR中的AddTR時就會出現nodeType是null或者不是一個物件的錯誤,但當我把
"var cloneTr = $(ths).parents('tr:first').clone(true);"換成"var cloneTr = $(ths).parents('tr:first').clone();"時,clone成功點擊不會出現錯誤,但是有些事件沒有加上,因此我必須加上"true",
有誰知道的幫我解決一下nodeType的錯誤問題,謝謝!

soarfe的主页 soarfe | 初学一级 | 园豆:146
提问于:2009-06-25 13:55
< >
分享
其他回答(1)
0

克隆一次后,同样的选择器就是会选择到两个对象,你可以试试在克隆前筛检为1个对象,即.clone()前面加一个.eq(0)

var cloneTr = $(ths).parents('tr:first').clone(true)改为var cloneTr = $(ths).parent('tr').clone(true)试试

斯克迪亚 | 园豆:4124 (老鸟四级) | 2009-06-25 14:03
0

可以直接写成 $("tr[name=moban]:first-child").clone();

倾城绝厉 | 园豆:4 (初学一级) | 2009-06-25 19:10
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册