본문 바로가기

Python_WEB/JavaScript

[부스트코스]Javascript 제어문 퀴즈 10

반응형

Q>

이번 강의에서 배운 코드를 약간 수정해서 첫 번째 하이퍼링크를 제외한 나머지 세 개의 하이퍼링크만 색깔이

바뀌도록 만들어보세요

 

A>

<!doctype html>
<html>

<head>
    <title>WEB1 - Welcome</title>
    <meta charset="utf-8">
</head>

<body>
    <h1><a href="index.html">WEB</a></h1>
    <input type="button" value="night" onclick="
    var target = document.querySelector('body');
    if (this.value === 'night') {
        target.style.background = 'black';
        target.style.color = 'white';
        this.value = 'day';

        var alist = document.querySelectorAll('a');
        var i = 1;
        while(i < alist.length) {
            alist[i].style.color = 'powderblue'
            i = i + 1;
        }
    } else {
        target.style.background = 'white';
        target.style.color = 'black';
        this.value = 'night';
        
        var alist = document.querySelectorAll('a');
        var i = 1;
        while(i < alist.length) {
            alist[i].style.color = 'blue'
            i = i + 1;
        }
    }
    ">
    <ol>
        <li><a href="1.html">HTML</a></li>
        <li><a href="2.html">CSS</a></li>
        <li><a href="3.html">JavaScript</a></li>
    </ol>
    <h2>WEB</h2>
    <p>The World Wide Web (abbreviated WWW or the Web) is an information space where documents and other web resources
        are
        identified by Uniform Resource Locators (URLs), interlinked by hypertext links, and can be accessed via the
        Internet.[1] English scientist Tim Berners-Lee invented the World Wide Web in 1989. He wrote the first web
        browser
        computer program in 1990 while employed at CERN in Switzerland.[2][3] The Web browser was released outside of
        CERN
        in 1991, first to other research institutions starting in January 1991 and to the general public on the Internet
        in
        August 1991.
    </p>
</body>

</html>

 

i의 초기값을 1을 주면 첫번째 원소를 건너뛰어서 나머지 원소값에 대해서만 스타일 시트가 적용된다.

 

https://www.boostcourse.org/cs124

 

자바스크립트의 시작

부스트코스 무료 강의

www.boostcourse.org

 

반응형