<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>実行タイミング</title>
<script>
/* 課題処理を追加 */
function background_black(){
document.body.style.color='white';
document.body.style.backgroundColor = "black";
}
function background_white(){
document.body.style.color='black';
document.body.style.backgroundColor = "white";
}
window.onload = function(){
var black = document.getElementById("black");
var white = document.getElementById("white");
black.addEventListener("click",background_black,false);
white.addEventListener("click",background_white,false);
}
</script>
</head>
<body>
<p>ボタンクリックにより背景色と文字色を変化</p>
<button id="black">背景黒</button>
<button id="white">背景白</button>
</body>
</html>
More than 3 years have passed since last update.
【JavaScript】「背景黒」ボタンを押すと、ページ全体の背景色が黒で文字色が白、「背景白」ボタンを押すと、ページ全体の背景色が白で文字色が黒となるようプログラムを書け
Last updated at Posted at 2021-05-11
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme