ボタンを押すたびに変更されるJavaScriptの作業信号がありますが、別のボタンを押すと自動的に色が自動的に変更されます。タイムコードを変更するボタンをコードに追加するにはどうすればよいですか?
私の現在のコードは次のようである:
<!DOCTYPE html>
<html>
<head>
<style>
#black {
background: black;
padding: 20px;
width: 150px;
height: 450px;
}
#red {
border-radius: 100px;
background: red;
width: 130px;
height: 130px;
position: relative;
top: 10px;
left: 10px;
}
#amber {
border-radius: 100px;
background: orange;
width: 130px;
height: 130px;
position: relative;
top: 20px;
left: 10px;
}
#green {
border-radius: 100px;
background: green;
width: 130px;
height: 130px;
position: relative;
top: 30px;
left: 10px;
}
</style>
</head>
<body>
<script>
var seq = [["red","grey","grey"],["red","orange","grey"],["grey","grey","green"],["grey","orange","grey"]];
var y = 0;
function lights() {
if (y < 4){
var current = seq[y];
var r = current[0];
var a = current[1];
var g = current[2];
document.getElementById("red").style.background= r;
document.getElementById("amber").style.background= a;
document.getElementById("green").style.background = g;
y++
} else {
y = 1
document.getElementById("red").style.background= "red";
document.getElementById("green").style.background= "grey";
document.getElementById("amber").style.background = "grey";
}
}
</script>
<div id="black">
<button onclick=lights()>Next cycle</button>
<div id="red"></div>
<div id="amber"></div>
<div id="green"></div>
</div>
</body>
</html>
スタックオーバーフローにいくつかのコード – pradeep1991singh
ようこそ提供してください!あなたは最初に[ツアー]を受け、良い質問をして[mcve]を作成することができます。そうすれば、私たちがあなたを助けやすくなります。 – Katie
いくつかの助けを得るためには、この問題に関連するHTML、CSS、JavascriptコードをGoogleに提供する必要があります。 – Lewis