2013-08-31 5 views
1

저는 jquery에 새로 익숙하지만 다음을 시도하고 있습니다. 링크를 클릭하고 replaceWith() 양식을 클릭하고 양식에서 제출을 클릭하면 두 번째 jquery 함수가 ajax 호출과 다른 replaceWith(). replaceWith() 및 두 번째 jQuery 함수

이 두 가지 기능

$(function addtop10fromuserpage() { 
    $(".addshowtotop10").click(function() { 
     var button = $(this); 
     button.replaceWith('<form><input class="addtop10userinput" type="text" name="seriesname" /><input type="submit" class="button small addtop10usersubmit" value="Add" /></form>'); 
    }); 
}); 


$(function addtop10fromuserpageshowadd() { 
    $(".addtop10usersubmit").click(function() { 
     var button = $(this); 

     var position = button.closest(".top-rating").find(".top-rating-text").html(); 
     alert('position'); 
    }); 
}); 

Bascially 자들은 개별적으로 호출되는 경우, 두 기능은 잘하지만 나는 replacewith 양식에서 두 번째 함수를 호출하는 경우, 그것은 작동하지 않습니다. 왜 그런가요?

감사합니다. 요소가 동적으로 생성되기 때문에

+0

http://api.jquery.com/on/ –

답변

0

당신은 내가 갈 것을주지

$(function addtop10fromuserpage() { 
    $(document).on('click', ".addshowtotop10", function() { 
     var button = $(this); 
     button.replaceWith('<form><input class="addtop10userinput" type="text" name="seriesname" /><input type="submit" class="button small addtop10usersubmit" value="Add" /></form>'); 
    }); 
}); 


$(function addtop10fromuserpageshowadd() { 
    $(document).on('click', ".addtop10usersubmit", function() { 
     var button = $(this); 

     var position = button.closest(".top-rating").find(".top-rating-text").html(); 
     alert('position'); 
    }); 
}); 
+0

이벤트 위임을 기반으로 핸들러를 사용해야합니다! 고맙습니다 – Callombert