2012-12-02 3 views
0
$("div[id^='BlockHeading']").live("click", function() { 

    var text = $(this).text().toString(); 
    if ($(this).next().css("display") == "none") { 
     $(this).empty(); 
     $(this).html("" + text + " <img src='../img/109041_25936_16_chevron_collapse_icon.png' height='12' width='12' style='float:right'>") 
     iframeresize(); 
     $(this).focus(); 
    } else { 
     $(this).empty(); 
     $(this).html("" + text + " <img src='../img/109041_25936_16_chevron_collapse_iconDown.png' height='12' width='12' style='float:right'>") 
     iframeresize(); 
     $(this).focus(); 
    } 
    jQuery(this).next(".content").slideToggle(100); 
}); 

이벤트가 발생한 후 IFRAME의 크기를 변경하려고합니다. 위의 예는 그러한 이벤트 중 하나를 보여줍니다. 함수를 호출하기 전에 또는 함수 자체 내에서 alert()을 실행하면 호출되는 함수 iframeresize()에서 문제가 발생하지만이 아니면 다음과 같은 경우에는 작동하지 않습니다 (방화 거리의 debug-window). 현재 ...경고()를 제거하면 스크립트 실행이 중지됩니다.

나는 무엇을 놓치고? iframeresize()에 대한

편집 코드 :

function iframeresize() { 
    $("#frame1", parent.document).css("height", $("#form1").height() + 100); 
    $("#container", parent.document).css("height", $("#form1").height() + 100); 
} 
+0

제 추측은 타이밍입니다. 삽입하려는 HTML 내부에서 'iframeresize'를 호출 해 볼 수 있습니까? – sje397

+0

확인. 나도 그 것을 시험하게 해주세요. .. – user1666443

+0

asing하는 것에 대해 유감스럽게 생각한다. 그러나 나는 그것을 어떻게한다. .. ??? – user1666443

답변

0

시간 초과에서 호출 시도하고 나머지 코드가 실행을 계속 할 수 있습니다.

... 
setTimeout(iframeresize, 10); 
... 
+0

아니요 ... 작동하지 않았습니다. – user1666443

0

어쨌든 새로운 html을 요소에 할당 했으므로 $(this).empty()이 삭제되었습니다. 이 코드를 테스트, 작동하는지 증명 (http://jsfiddle.net/Zt3eP/17/) 하며,이 코드의 다른 부분 문제 및 표시하지 무엇가있을 수 있습니다.

$("div[id^='BlockHeading']").live("click", function() { 
    var text = $(this).text().toString(); 
    if ($(this).next().css("display") == "none") { 
     $(this).html("" + text + " <img src='../img/109041_25936_16_chevron_collapse_icon.png' height='12' width='12' style='float:right'>") 
     iframeresize(); 
     $(this).focus(); 
    } else { 
     $(this).html("" + text + " <img src='../img/109041_25936_16_chevron_collapse_iconDown.png' height='12' width='12' style='float:right'>") 
     iframeresize(); 
     $(this).focus(); 
    } 
    $(this).next(".content").slideToggle(100); 
}); 
function iframeresize(){ 
    console.log('resize'); 
} 
​ 
관련 문제