Помогите составить цикл и функцию на все кнопки GetButton(),
т.к будет очень много кнопок.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Button</title>
<script>
var strLED1 = "", strLED2 = "", strLED3 = "";
var LED1_state = 0,LED2_state = 0,LED3_state = 0;
function GetButton1() {
if (LED1_state === 1) {
LED1_state = 0;
strLED1 = "&LED1=0";
document.getElementById("LED1").innerHTML = " OFF ";
document.getElementById("ld1").innerHTML = "OFF";
} else {
LED1_state = 1;
strLED1 = "&LED1=1";
document.getElementById("LED1").innerHTML = " ON ";
document.getElementById("ld1").innerHTML = "ON";
}
}
function GetButton2() {
if (LED2_state === 1) {
LED2_state = 0;
strLED2 = "&LED2=0";
document.getElementById("LED2").innerHTML = " OFF ";
document.getElementById("ld2").innerHTML = "OFF";
} else {
LED2_state = 1;
strLED2 = "&LED2=1";
document.getElementById("LED2").innerHTML = " ON ";
document.getElementById("ld2").innerHTML = "ON";
}
}
function GetButton3() {
if (LED3_state === 1) {
LED3_state = 0;
strLED3 = "&LED3=0";
document.getElementById("LED3").innerHTML = " OFF ";
document.getElementById("ld3").innerHTML = "OFF";
} else {
LED3_state = 1;
strLED3 = "&LED3=1";
document.getElementById("LED3").innerHTML = " ON ";
document.getElementById("ld3").innerHTML = "ON";
}
}
</script>
</head>
<body>
<p>30: <button type="button" id="LED1" onclick="GetButton1()"> OFF </button> <span class="value" id="ld1">...</span></p>
<p>31: <button type="button" id="LED2" onclick="GetButton2()"> OFF </button> <span class="value" id="ld2">...</span></p>
<p>32: <button type="button" id="LED3" onclick="GetButton3()"> OFF </button> <span class="value" id="ld3">...</span></p>
</body>
</html>