2013-12-09 71 views
0

我試圖創建一個jQuery函數框中選擇克隆和追加一個文本字段,並進入一個div的底部,像這樣:jQuery的克隆和觸發創建

$(".inline-form .copyIng:first-child").clone().appendTo(".inline-form"); 
$(".copyIng").trigger("create"); 

看到這個:http://jsfiddle.net/rxwL6/

但是,這兩個元素得到了克隆兩次,看起來有線,任何想法,爲什麼會發生這種情況?

問候:)

我回答我自己的問題

遺憾,但解決的辦法是這樣的:

$(document).ready(function(){ 
    $("#newIng").click(function(){ 
    $(".inline-form .copyIng:first-child").clone().appendTo(".inline-form"); 
    }); 

    $("#newOve").click(function(){ 
    $('<div class="ove"><input type="text" name="c[]" class="field" placeholder="Overskrift"></div>').appendTo(".inline-form"); 
    $(".field").textinput(); 
    }); 
}); 
+0

是不是你想要什麼http://jsfiddle.net/rxwL6/2/? – YD1m

+0

沒錯,但後來當我添加一個文本字段時,我需要觸發創建。 – Sims

回答

0

好像你應該使用refrash事件。 create事件適用於增強包含一個或多個小部件的原始標記。 refresh方法應該用於編程操作的現有(已增強的)小部件,並且需要更新UI以匹配。

的jsfiddle:http://jsfiddle.net/rxwL6/5/

+0

好的,太好了,但爲什麼我不能從創建的下拉列表中選擇任何東西? – Sims