이것은 shan이고 저는 javascript 멍청이이고 여기서는 예제로 qa 코드를 사용하려고합니다. div 요소에 작은 자바 스크립트 콘텐츠를로드하려고하지만 위의 코드는 도움이되지 않습니다.div를 사용하여 div에 내용을로드 할 수 없습니다.
<html>
<head>
<title>
using d for statement
</title>
<script>
function displaytext() {
var loopindex=0;
var sum=0;
for (var loopindex=1; loopindex <=100; loopindex++) {
sum +=loopindex;
};
document.getElementById('targetdiv').innerhtml="adding 1 to 100 gives "+sum;
}
</script>
</head>
<body>
<div id="targetdiv">
</div>
</body>
</html>
여기서 'displaytext()'는 (는) 어디에 호출됩니까? 'document.onload()'호출로 그것을 감쌀 수도있다. – Schleis
은 'innerHTML'에서'innerhtml'을 변경합니다. @Schleis가 제안한대로'displaytext()'함수를 호출하십시오. – Ragnarokkr