単純なフォームがあり、各行は3つの入力フィールドで構成されています。それらのフィールドの1つで、jscolor.jsを使用します(フィールドにはがありclass="color"
、したがってJSをバインドします)。
ただし、jQueryを使用して新しい行を追加するdelegate()
と、入力フィールドがJSにバインドされず、期待される機能がありません。http://jsfiddle.net/alexwald/qARzP/
<script>
var line = '<li class="form_line" id="line">
<span>
<label for="item">Item:</label>
<input type="text" required="required" placeholder="what item is this?" id="item" name="item[]>
</span>
<span>
<label for="amount">Amount: </label>
<input required="required" type="number" id="amount" name="amount[]>
</span>
<span>
<label for="color">Color: </label>
<input type="text" required="required" class="color {pickerClosable:true, hash:true ,pickerFace:3,pickerBorder:0}" id="color" name="color[]">
</span>
</li>';
$(document).ready(function() {
$("form").delegate(".add", "click", function(){
$('ul').append(line);
}); // end of adding
}); //end of main func
</script>
問題は次のいずれかにあると思います。
line
変数を定義する方法、または- で不適切なセレクターを使用しているので、 ..
.delegate
ではなく別のものにする必要があります。form
どんな助けでも大歓迎です。