서버에서 HTML 양식 요소를로드하는 jQuery / AJAX 함수가 있습니다. 양식의 필드는 다양합니다. 로드가 완료된 후 사용 가능한 첫 번째 입력 필드에 포커스를 설정하고 싶습니다. 나는 시도했다 :
$(':input:enabled:visible:first').focus();
그러나 이것은 작동하지 않습니다 :( jQuery에서 입력 필드를 어떻게 처리 할 수 있는지 잘 모르겠습니다. 반환 된 요소의 ID를 모릅니다.
내 함수는 아래와 같지만 my_html 변수에는 여러 개의 간단한 입력 필드가 포함되어 있습니다.
<input type='text' name='test' value='prefilled' />
AJAX 기능 :
$.loadIDX = function (idx, position){
var url = 'URL HERE';
$.ajax({
url: url,
type: "POST",
data: {
idx:idx,
position:position
},
dataType: 'json',
success: function(data) {
if(data.status=='request'){
var my_html = '<div id="slide_in"><div id="please_enter_'+idx+'" class="please_enter">Please enter:</div><form id="cform_'+idx+'">';
// loop through json & create html input form fields
$.each(data, function(key, val) {
if(key!='status'){
my_html += val;
}
})
// close up the form
my_html += '<input class="submit_button" type="button" value="ok" onClick="postForm('+idx+','+position+')" /></form></div>';
// place the new HTML into the DIV
$('#yn_'+idx).html( my_html );
// set focus... HOW?
$(':input:enabled:visible:first').focus();
} else {
$.closeIDX(idx);
}
}
});
}
어때
$('#yn_'+idx).html( my_html ).find('input:first').focus();
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다