2013-06-21 48 views
0

開始:我對前端開發非常新(它被添加到我的java後端工作:))。我有一個模式,打開頁面上有兩行的表 - 每個有2個輸入和一個選擇框。如果你點擊一個按鈕....它應該添加具有相同元素的另一行。他們使用這樣做:有一個隱藏着元素的表格頁腳(從行開始:<tr>),然後當您單擊該按鈕時,它會調用表格主體和.append頁腳。然後調用三個元素的attr並更改id和名稱。由於某種原因,如果頁腳未被隱藏......下拉菜單可以正常工作,但複製版本不會。我們調查了名稱,值等。這些值在呈現的html中...下拉菜單沒有打開。不能追加選擇框與JQuery

所以,現在我正在努力做的......我覺得可能會更乾淨。用html創建一個變量...並在每次單擊按鈕時追加。但是select元素有一個標籤被寫入...所以我不知道這是否是問題,但是每次我嘗試將它添加到混合中......有關於意外標記的錯誤(<)。如果我採取一條線開始< dfm:catombobox >遠 - 它的作品...任何人有想法來幫助我添加「catombobox」這是選擇與標籤? PS:如果我把報價拿走,只是將該行復制到原始表格中......它可以工作?

var newRow = '<tr>'+ 
       '<td nowrap="nowrap"><strong>R</strong> <input class="amount input-small" style="margin-top: 8px;margin-bottom: 0;" type="text"/></td>'+ 
       '<td nowrap="nowrap" style="padding-top: 7px;">'+ 

       '<dfm:catombobox cssClass="input-medium" id="CategoryId_Test" name="CategoryName_Test" showEmptyCategory="true" showGroups="true" value=""/>'+ 

       '</td>'+ 
       '<td><input class="input-medium" style="margin-top: 8px;margin-bottom: 0;" type="text"/></td>'+ 
       '<td><a class="remove" href="#"><i class="icon-remove"></i></a></td>'+ 
       '</tr>'; 
      $("#mytable tbody").append(newRow); 

回答

0

嘗試使用select代替DFM的:catombobox

+0

感謝。不幸的是,選擇框中的數據有點複雜。它來自不同的層面,標籤不僅在設計時考慮到了公司的造型標準,而且還考慮到將正確的選項和組合放在下面。我測試了我的html中的確切代碼行,它的工作原理。所以看起來問題是如何讓變量或「apped」認識到這應該像hmtl頁面一樣處理? – user990855

+0

然後在這種情況下只需使用:$(「#mytable tbody」)。append(newRow);通過將它綁定到按鈕單擊事件 –

0

這裏檢查其做工精細

adding new rows to table

var newRow = '<tr>' + 
    '<td nowrap="nowrap"><strong>R</strong> <input class="amount input-small" style="margin-top: 8px;margin-bottom: 0;" type="text"/></td>' + 
    '<td nowrap="nowrap" style="padding-top: 7px;">' + 

    '<dfm:catombobox cssClass="input-medium" id="CategoryId_Test" name="CategoryName_Test" showEmptyCategory="true" showGroups="true" value=""/>' + 

    '</td>' + 
    '<td><input class="input-medium" style="margin-top: 8px;margin-bottom: 0;" type="text"/></td>' + 
    '<td><a class="remove" href="#"><i class="icon-remove"></i></a></td>' + 
    '</tr>'; 
$("#btn").on('click',function(){ 
    $("#mytable tbody").append(newRow); 
}) 
+0

因此,目前變量聲明以及append在click函數中:$(「#add」)。click(function(){......})。我應該有變量全球然後只附加在這個功能?這有什麼不同嗎? – user990855

+0

好的 - 我現在只能打開你的例子。如果你看我的表格行......有三列。第1列和第3列有輸入。第2列是下拉菜單。你的例子也沒有顯示選擇框? – user990855

+0

http://jsfiddle.net/Faheem66/XMBZk/3/ – FLF