HTML에 height
속성이 없으면 그렇게 할 수 없습니다.
//<![CDATA[
var doc = document, bod = doc.body, IE = parseFloat(navigator.appVersion.split('MSIE')[1]);
bod.className = 'js';
function gteIE(version, className){
if(IE >= version)bod.className = className;
}
function E(e){
return doc.getElementById(e);
}
function getPropertyFrom(p, e){
return getComputedStyle(e).getPropertyValue(p) || e.currentStyle[p];
}
E('P2').style.height = getPropertyFrom('height', E('P1'))+'px';
//]]>
jQuery를 같이 다음과 같습니다 : 순수 자바 스크립트에서 창 크기 조정에
//<![CDATA[
$('#P2').css('height', $('#P1').height()+'px');
//]]>
:
onresize = function(){
E('P2').style.height = getPropertyFrom('height', E('P1'))+'px';
}
창 순수 자바 스크립트를 사용하는 경우,이 같이해야 할 것이다 jQuery에서 크기 조정 :
$(window).resize(function(){
$('#P2').css('height', $('#P1').height()+'px');
});
참고 : 외부 자바 스크립트를 사용해야하므로 캐시됩니다. window
은 암시 적이므로 window.onresize = function(){}
, window.document
, window.open()
등을 쓸 필요가 없습니다. 원할 경우 window
개체를 참조 할 때 window
을 그대로 두십시오.
DOM/이미지 준비 /로드 될 때 실제로 메서드를 호출합니까? –