티스토리 뷰
반응형
특정 form에 소속되어 있는 elements를 가져와서 해당 input,select, textarea에 대한
vaildation을 실행해 주는 작업이 필요할 때가 있는데, 이럴 때 아래와 같은 방식으로 가져오면
편하게 가져올 수 있다.
1 2 3 4 5 6 7 8 9 | //저장버튼 클릭시에 validation 실행 $("#save_btn").bind("click",function(){ var targetForm = $("#frm_req_adjust_price .__required"); $.each(targetForm, function(index, elem){ alert("targetName : " + $(this).attr("name") + ", targetID : " + $(this).attr("id") + ", targetType : " + $(this).attr("type")); //validation function 실행 }); }); | cs |
또한 화면 전체에 대한 input, select, textarea를 가져오고 싶으면 아래와 같이 실행하면 된다.
1 2 3 4 5 6 | $('input, select, textarea').each( function(index){ var input = $(this); alert('Type: ' + input.attr('type') + 'Name: ' + input.attr('name') + 'Value: ' + input.val()); } ); | cs |
반응형
'Programming > 제이쿼리(Jquery)' 카테고리의 다른 글
jquery form submit 시에 이벤트 적용 (0) | 2015.07.22 |
---|---|
jquery에서 체크된 체크박스의 순서 가져오기(index) (0) | 2015.06.17 |
jquery에서 radio button 컨트롤 하기 (0) | 2015.06.04 |
jquery each 사용하기 (0) | 2015.05.19 |