JQueryを使用して、リンクをクリックして追加の入力フィールドを作成しています。現在のところ、ページ読み込み時に作成されたフィールドで正常に動作するオートコンプリートプラグインが実装されています。ユーザーが新しいフィールドを追加すると、オートコンプリートはその特定のフィールドでは機能しません。私は誰かが私にそれを働かせる方法を理解するのを助けることができるかどうか疑問に思っていただけです。JQueryで追加フィールドのオートコンプリート
<script type="text/javascript">
$(document).ready(function() {
$('#addingredient').click(function() {
$('<li />').append('<input type="text" class="ingredient" name="ingredient[]" id="ingredient[]" size="60" />')
.append('<input type="text" class="amount" name="amount[]" id="amount[]" size="5" />')
.append('<select class="unit" name="unit[]" id="unit[]"><?=$units ?></select>')
.appendTo('#ingredients')
.hide()
.fadeIn('normal');
});
</script>
<script>
$(document).ready(function(){
var data = "http://mywebsite.com/ingredients.php";
$(".ingredient").autocomplete(data);
});
</script>
<ul id="ingredients">
<li><input type="text" class="ingredient" name="ingredient[]" id="ingredient[]" size="60" /><input type="text" class="amount" name="amount[]" id="amount[]" size="5" /><select class="unit" name="unit[]" id="unit[]"><?=$units ?></select></li>
<li><input type="text" class="ingredient" name="ingredient[]" id="ingredient[]" size="60" /><input type="text" class="amount" name="amount[]" id="amount[]" size="5" /><select class="unit" name="unit[]" id="unit[]"><?=$units ?></select></li>
<li><input type="text" class="ingredient" name="ingredient[]" id="ingredient[]" size="60" /><input type="text" class="amount" name="amount[]" id="amount[]" size="5" /><select class="unit" name="unit[]" id="unit[]"><?=$units ?></select></li>
</ul>
使用tvanfossonの答え。 – Kezzer