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