티스토리 뷰

JavaScript

[JavaScript] 7식 - if

baegofda_ 2020. 7. 12. 21:45

* if

if ("10" === 10) {                          // == 는 값만 비교하고 ===는 형식까지 비교한다. 
    console.log("hi");
} else if ("10" === "10") {
    console.log("ha");
} else {
    console.log("alalalal");
}

if (20 > 5 && "nicolas" == "nicolas") {        // || 은 or이고 &&는 and
    console.log("haha");
} else {
    console.log("lala");
}

* if + click

const title = document.querySelector("#title");

const BASE_COLOR = "rgb(250, 128, 114)";
const OTHER_COLOR = "#FF1493";


function handleclick() {
    const currentColor = title.style.color;
    if (currentColor === BASE_COLOR) {
        title.style.color = OTHER_COLOR;
    } else {
        title.style.color = BASE_COLOR;
    }
}

function init() {
    title.style.color = BASE_COLOR;
    title.addEventListener("click", handleclick);
}
init();

* if + mouseenter

function init() {
    title.style.color = BASE_COLOR;
    title.addEventListener("click", handleclick);
}
init();

const title = document.querySelector("#title");

const BASE_COLOR = "rgb(250, 128, 114)";
const OTHER_COLOR = "#FF1493";


function handleclick() {
    const currentColor = title.style.color;
    if (currentColor === BASE_COLOR) {
        title.style.color = OTHER_COLOR;
    } else {
        title.style.color = BASE_COLOR;
    }
}

function init() {
    title.style.color = BASE_COLOR;
    title.addEventListener("mouseenter", handleclick);
}
init();

* HTML javascript DOM envent MDN

 

'JavaScript' 카테고리의 다른 글

[JavaScript] 9식 - setInterval (clock)  (0) 2020.07.12
[JavaScript] 8식 - classList, toggle  (0) 2020.07.12
[JavaScript] 5식 - Function (함수)  (0) 2020.07.12
[JavaScript] 4식 - Array  (0) 2020.07.12
[JavaScript] 2식 - Start JavaScript  (0) 2020.07.12
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
글 보관함