4
HTML 페이지에 양식을 표시하는 버튼이 있습니다. 나는 동적으로 생성되지 않은 다른 형태의 데이터를 얻을 수 있기 때문에동적으로 생성 된 양식에서 양식을 가져올 수 없습니다.
function getFormData($form){
var unindexed_array = $form.serializeArray();
var indexed_array = {};
$.map(unindexed_array, function(n, i){
indexed_array[n['name']] = n['value'];
});
return indexed_array;
}
기능이 잘 작동하는 것 같다 : I 양식에서 데이터를 가져 오는 기능을 가지고있다. 단추를 클릭하면 양식을 만들 수 있습니다.
var new_form = document.createElement('form');
new_form.id = "new_form";
// (...) all the inputs for the form
// and I append to an existent div
existent_div.appendChild(new_form);
// and then the inputs
new_form.appendChild(input1); (...)
폼 데이터를 가져 오는 데 필요한 다른 단추가 있습니다. 이 함수를 호출하면 함수의 중간에 다음과 같이 나타납니다.
var new_form_info = getFormData($("#new_form"));
// I get an empty object...
왜 이런 일이 발생합니까? 나는 경험이 풍부한 프로그래머가 아니므로 실수로 유감입니다 ...
당신은 구문 전자가 rror. 당신은'new_form.appendChild (input)'을 사용해야합니다. 콘솔에''append_child "'가 함수가 아님을 확인하십시오. – synthet1c
@ synthet1c 오 저것을 보지 못했습니다. 오타였습니다. Ty –
'$ ("# new_form")''getFormData' 함수에 전달되기 바로 전에 어떤 객체를 선택기'$ ("# new_form")에서 가져 옵니까? –