분류
javascript
단락의 배경색을 설정하는 JavaScript 프로그램 작성
본문
HTML :
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>단락의 배경색을 설정하는 JavaScript 프로그램 작성</title>
</head>
<body>
<input type="button" value="Click to set paragraph background color" onclick="set_background()">
<p>365ok.co.kr JavaScript Exercises</p>
<p>365ok.co.kr PHP Exercises</p>
</body>
</html>
JS :
function set_background() {
docBody = document.getElementsByTagName("body")[0];
//Get all the p elements that are descendants of the body
myBodyElements = docBody.getElementsByTagName("p");
// get the first p elements
myp1 = myBodyElements[0];
myp1.style.background = "rgb(255,0,0)";
// get the second p elements
myp2 = myBodyElements[1];
myp2.style.background = "rgb(255,255,0)";
}
- 이전글테이블에 행을 추가하는 JavaScript 함수를 작성하십시오. 17.12.30
- 다음글다음 양식의 성과 이름을 얻기위한 JavaScript 함수를 작성하십시오. 17.12.30