사용자의 클라이언트 너비를 고려하여 페이지 너비를 변경하는 스크립트를 작성하려고합니다. 그것은이 같은 뭔가 :JavaScript를 통해 본문 태그 스타일 변경
function adjustWidth() {
width = 0;
if (window.innerHeight) {
width = window.innerWidth;
} else if (document.documentElement && document.documentElement.clientHeight) {
width = document.documentElement.clientWidth;
} else if (document.body) {
width = document.body.clientWidth;
}
if (width < 1152) {
document.getElementsByTagName("body").style.width="950px";
}
if (width >= 1152) {
document.getElementsByTagName("body").style.width="1075px";
}
}
window.onresize = function() {
adjustWidth();
};
window.onload = function() {
adjustWidth();
};
나는 방화범이 끌려에서 오류가이 스크립트 :
document.getElementsByTagName("body").style is undefined
지금 내 질문은, 내가 어떻게 신체의 스타일에 액세스 할 수 있습니다
? CSS 시트에서 selector와 width 속성이 정의 되었기 때문입니다.
시도 **'getComputedStyle (요소) 스타일] ** '예'window.getComputedStyle ** (는 document.body) .width' ** .. . learn http://javascript.info/tutorial/styles-and-classes-getcomputedstyle – KingRider