상황 :
아무리 들여다 보아도 분명 폼으로 쌓여있는 것이 분명한데 값을 가져오지 못하는 상황이었습니다.
원인 :
간소화해보면 아래와 같은 html 페이지가 있을때
div 태그의 위치가 맞지 않게 되면 jQuery에선 해당 input의 값을 가져오지 못합니다..
해당 폼의 html 값을 찍어보고 나서야 이해했습니다.
( 전혀 예상치 못했습니다..;; html 페이지 라인의 압박으로.. 차마 보지 못했던.. 사실은 엉성한 html 들여쓰기의 문제도 있었지요.. )
test Url : http://www.uhoon.co.kr/test/1219.html
<!DOCTYPE html> <html> <head> <title>test</title> <script src="http://code.jquery.com/jquery-latest.min.js"></script> <meta http-equiv="content-type" content="text/html;charset=UTF-8"> </head> <script type="text/javascript"> <!-- $(function() { $("#btn").on("click",function(){ alert($("form[name='frmA'] input[name='inputAA']").val()); alert($("form[name='frmA']").html()); }); }); //--> </script> <body > <div> <form name="frmA" > <input type="text" name="inputA" /> <input type="text" name="inputB" /> </div> <input type="text" name="inputC" /> <div> <input type="text" name="inputD" /> </div> <input type="text" name="inputAA" /> <input type="text" name="inputBB" /> <input type="text" name="inputCC" /> <input type="text" name="inputDD" /> <div> </form> </div> <input type="button" id="btn" value="폼 확인" /> </body> </html>