jQuery 대화 상자를 사용하여 다른 페이지를 기본 페이지의 대화 상자에로드합니다. 다른 페이지에는 앵커 태그가있을 수 있으며로드 함수의 completed 이벤트를 사용하여 내용이로드 된 div의 모든 앵커 태그를 선택합니다. 그런 다음 기본 페이지에 포함 된 div에 내용이로드되도록 앵커 태그 클릭 이벤트 처리기를 연결합니다. 그러나 이것은 두 번만 작동합니다. 아래 예제 코드를 실행하면 Partial1이 대화 상자에 나타납니다. 대화 상자에서 Partial2 링크를 클릭하면 Partial1이 대화 상자에로드되지만 이번에는 Partial2 링크를 클릭하면 기본 페이지에로드됩니다. 내가 뭘 잘못하고/또는 파악하지 못하고 있습니까? 자바 스크립트 이벤트 및 재귀 문제
홈/색인 :
<a href="/Home/Partial1" id="help">Partial 1</a>
<div id="dialog" style="display: none">
</div>
<script type="text/javascript">
$(document).ready(function() {
$("#help").click(function() {
adjustNestedAnchors($(this));
$("#dialog").dialog().show();
return false;
});
function adjustNestedAnchors(element) {
$("#dialog").load($(element).attr("href"),
function (response, status, xhr) {
if (status != "error") {
$("#dialog a").click(function() {
$("#dialog").load($(this).attr("href"), adjustNestedAnchors($(this)));
return false;
});
}
});
}
});
</script>
홈/Partial1
This is a sample partial view, which has a link back to <a href="/Home/Partial2">Partial2</a>.
홈/Partial2
This is a sample partial view, which has a link back to <a href="/Home/Partial1">Partial1</a>.
위대한 작품입니다! 내 오류 및 함수 이름 제안을 지적 해 주셔서 감사합니다! – codechurn
@Art : 오신 것을 환영합니다! – ruakh