<script src="js/jquery-3.7.1.min.js"></script>
<style type="text/css">
button{
font-size: 2rem;
}
</style>
<body style="font-size: 2.4rem; text-align: center;">
<p>
<button id="red">紅色</button>
<button id="orange">橘色</button>
<button id="yellow">黃色</button>
<button id="green">綠色</button>
<button id="blue">藍色</button>
<button id="purple">紫色</button>
</p>
</body>
<script type="text/javascript">
$(document).ready(function(){
});
</script>
<script>
$(document).ready(function(){
$("button").on("click", function(){
});
});
</script>
<script>
$(document).ready(function(){
$("button").on("click", function(){
alert($(this).attr("id"));
});
});
</script>
<script>
$(document).ready(function(){
$("button").on("click", function(){
//alert($(this).attr("id"));
//
color = $(this).attr("id"); //設定一個變數color 來儲存
$("body").css("background-color", color); //設定成<body>的背景色
});
});
</script>
<style type="text/css">
button{
font-size: 2rem;
}
body{
transition-duration: 1s;
}
</style>