+ 3
How to make button active after click and turn off it after second click?
2 odpowiedzi
+ 2
<!DOCTYPE html>
<html>
<style>
input {
height:50px;
width:100px;
}
</style>
<body>
<center><input type="button" id="button" onclick="myfunc();" value="something"></input></center>
<div></div>
<script>
var i=0;
var n = 0;
function myfunc () {
var button = document.getElementById("button");
if (i==0) {
button.style.backgroundColor="";
i++;
n++;
}
else {
button.style.backgroundColor="green";
i=0;
}
document.querySelector("div").innerHTML = "<p>n="+n+"</p><p>n="+i+"</p>";
}
</script>
</body>
</html>