jQuery Autocomplete을 사용하여 제품 조회를하고 있습니다. 다음 코드를 사용하여 목록에서 선택을 시행합니다.몇 가지 경고문이있는 경우에만 자바 스크립트 코드가 다르게 동작합니다.
$(".force-selection").blur(function(e) {
var value = $(this).val();
//check if the input's value matches the selected item
alert($(this).val());
alert($(this).data('selected-item'));
if(value != $(this).data('selected-item')) {
//they don't, the user must have typed something else
$(this)
.val('') //clear the input's text
.data('selected-item', ''); //clear the selected item
}
});
위의 코드는 두 개의 경고문이 제거 된 경우에만 작동합니다. 두 가지 경고문이있는 경우에만 동작이 변경되는 이유는 무엇입니까?
인종? 아마도 경보 상자가 표시되는 동안 다른 발사가있을 것입니까? – Piskvor
당신은 입력 상자'blur' 이벤트가 아니라 자동 완성의 [change] (http://jqueryui.com/demos/autocomplete/#event-change) 이벤트를 처리해야합니다. – jbabey
자동 완성 조회가 비동기입니다. 그 때까지 기다려야하며 경고는 코드를 충분히 오랫동안 정지시킵니다. – Bergi