jquery 2.0 on 동적 요소에 귀속 이벤트

1131 단어
$(document).on("change","#pageSize_out",function(){  
        if($("#page_out").val()!=0){  
             $("#pageSize").val($(this).val());  
    }  
})  ;
참고:
As this answers receives a lot of attention, here are two supplementary advises :
1) When it's possible, try to bind the event listener to the most precise element, to avoid useless event handling.
That is, if you're adding an element of class  b  to an existing element of id  a , then don't use
$(document.body).on('click', '#a .b', function(){

but use
$('#a').on('click', '.b', function(){

2) Be careful, when you add an element with an id, to ensure you're not adding it twice. Not only is it "illegal"in HTML to have two elements with the same id but it breaks a lot of things. For example a selector  "#c"  would retrieve only one element with this id.
간단하게 말하자면 부자 관계를 명확히 해야 하며, 직접 문서를 사용하지 마라. 하위 요소가 문서에 추가되지 않는 한

좋은 웹페이지 즐겨찾기