티스토리 뷰

반응형



특정 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


반응형
반응형
최근에 올라온 글
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28