๋ฆฌํํ ๋ง
<input id="night_day" type="button" value="night" onclick="
var target = document.querySelector('body');
if(document.querySelector('#night_day').value === 'night'){
target.style.backgroundColor = 'black';
target.style.color = 'white';
this.value = 'day';
} else {
target.style.backgroundColor = 'white';
target.style.color = 'black';
this.value = 'night';
}
">
var์ ์ฌ์ฉํ์ฌ ์ค๋ณต์ ์ ๊ฑฐํ ์ ์๋ค.
<input type="button" value="night" onclick="
if(this.value === 'night'){
document.querySelector('body').style.backgroundColor = 'black';
document.querySelector('body').style.color = 'white';
this.value = 'day';
} else {
document.querySelector('body').style.backgroundColor = 'white';
document.querySelector('body').style.color = 'black';
this.value = 'night';
}
">
this.value๋ฅผ ์ฌ์ฉํ๋ฉด ๋ฒํผ์ ๋๋ฌ๋ night์์ day๋ก ์๋ฐ๋์๋ ํ์์ ๊ณ ์น ์ ์๋ค.
'๐ค Language > ๐จ JavaScript' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
JS. ํจ์ (0) | 2022.01.08 |
---|---|
JS. ๋ฐฐ์ด๊ณผ ๋ฐ๋ณต๋ฌธ (0) | 2022.01.08 |
JS. ์กฐ๊ฑด๋ฌธ (0) | 2022.01.07 |
JS. ๋น๊ต ์ฐ์ฐ์์ Boolean ๋ฐ์ดํฐ ํ์ (0) | 2022.01.07 |
JS. ์ ์ดํ ํ๊ทธ ์ ํํ๊ธฐ & querySelector๋ฅผ ์ด์ฉํ ๋คํฌ๋ชจ๋ (0) | 2022.01.06 |