Please Enable JavaScript!
Gon[ Enable JavaScript ]

반응형
화면이 로딩되면 자바스크립트 함수 init() 를 호출하게 된다.
이 함수의 역활은 화면에 로딩된 3개의 이미지 정보를 DOM 객체를 이용해 가져온후
배열에 담고 그 배열을 반복하여 이미지 정보 문자열을 만든다.
그렇게 만든 정보는 div 태그 id = output 사이에 html 문자열을 삽입해서 표현해준다.

<script type="text/javascript">

<!--

function init()

{

  var arrImages = new Array(3);

  arrImages[0] = document.getElementById("image1");

  arrImages[1] = document.getElementById("image2");

  arrImages[2] = document.getElementById("image3");

  var objOutput = document.getElementById("output");

  var strHtml = "<ul>";

  for (var i = 0; i < arrImages.length; i++)

    strHtml += "<li>image" + (i+1) +

            ": height=" + arrImages[i].height +

            ", width=" + arrImages[i].width +

            ", style.height=" + arrImages[i].style.height +

            ", style.width=" + arrImages[i].style.width +

            "<\/li>";

            "<\/ul>";

  objOutput.innerHTML = strHtml;

}

//-->

</script>

 

</head>

<body onload="init();">

<p>Image 1: no height, width, or style <br>

    <img id="image1" src="http://www.mozilla.org/images/mozilla-banner.gif">

</p>

<p>Image 2: height="50", width="500", but no style <br>

    <img id="image2" src="http://www.mozilla.org/images/mozilla-banner.gif"

         height="50" width="500">

</p>

<p>Image 3: no height, width, but style="height: 50px; width: 500px;"<br>

    <img id="image3" src="http://www.mozilla.org/images/mozilla-banner.gif"

         style="height: 50px; width: 500px;">

</p>

 

<div id="output"> </div>


결과 화면이다.

반응형
Posted by 녹두장군1
,