JQuery에 문제가 있습니다. 사용자가 자동 완성 드롭 다운 메뉴 <input class="itemCode">
에서 항목을 선택한 후에 <input class="itemDescription">
을 채워야합니다. 사용자가 item
을 선택할 때만 JQuery가 제대로 작동하며 1 행과 2 행의 입력에 모두 동일한 Item Description이 채워집니다. 나는 그 두 가지 모두가 동일한 클래스를 가지고있는 itemDescription
입력이라고 생각한다. 그러나, 나는 그것을 고치는 방법을 모르겠다. 어떤 도움이라도 대단히 감사하겠습니다!JQuery 자동 완성은 선택시 모든 행을 채 웁니다.
<table class="table">
<thead>
<tr>
<td >Item Code</td>
<td >Description</td>
</tr>
</thead>
<tbody>
<tr>
<td class=""><input class="itemCode"></td>
<td class=""><input class="itemDescription"></td>
</tr>
<tr>
<td class=""><input class="itemCode"></td>
<td class=""><input class="itemDescription"></td>
</tr>
</tbody>
</table>
<script>
$(function() {
$(".itemCode").autocomplete({
source: function(request, response) {
$.ajax({
url: "item-search.php",
dataType: "json",
data: {
term: request.term
},
success: function(data) {
response(data);
}
});
},
minLength: 1,
select: function(event, ui) {
$(".itemDescription").val(ui.item.label);
}
});
});
</script>
은 매력처럼 작동합니다! 감사! – Luke
'itemPrice'와 같은 추가 필드를 추가하면 구문이 어떻게 생겼을까요? 이것을 시도하면 : $ (this) .parent(). next(). children (". itemDescription") .val (ui.item.itemDescription); \t $ (this) .parent(). next(). children (". itemCost") .val (ui.item.itemCost); ' 새로운 필드'itemPrice'는 채워지지 않습니다. 감사! – Luke
'.next()'를 추가하거나 편집 된 솔루션을 사용할 수 있습니다. 나는 좀 더 일반적인 것처럼 편집 된 솔루션을 제안 할 것이다. –