2011-04-26 66 views
1

我在某些onclick函數中有一個任務。我有一個表,其中每列包含一個下拉列表或文本框。其中一列包含一個按鈕。如果我用dropdownlist單擊該按鈕的行,包含添加按鈕的文本框必須動態添加爲下一行。我可以這樣做嗎?哪個更好的JavaScript或jQuery ..plz幫助我..在javascript中使用onclick函數動態添加行

回答

2

你可以嘗試以下

在該行的onclick添加的功能

function cloneRow(event){ 
    var tar_ele; 
    if ($.browser.msie) { 
    // IE takes SRCELEMENT for event source. 
    // may the force shred IE. 
     tar_ele = $(event.srcElement); 
    } else { 
     tar_ele = $(event.target); 
    } 
    // Now take the parent of the clicked item as the item is a button in a row 
    var row = tar_ele.parent(); 
    // Now clone the row and add it to the parent. 
    row.clone().appendTo(row.parent()); 
} 

希望這有助於。

0

你可以試試這個:

$('button-id').click(function() { 
    $('container-id').after('<input /><select />'); 
}); 

類似的東西,將你添加的輸入和選擇框新的一行到容器或你的表的末尾。