Փոփոխականով տարբերակ
Կոդ:
<script>
var x;
function run() {
x = document.getElementById("demo").style.background;
if (x=="blue") {
document.getElementById("demo").style.background="green";}
else {document.getElementById("demo").style.background="blue";}
}
</script>
Առանց փոփոխական տարբերակ
Կոդ:
<script>
var x;
function run() {
if (document.getElementById("demo").style.background=="blue") {
document.getElementById("demo").style.background="green";}
else {document.getElementById("demo").style.background="blue";}
}
</script>
Էջանիշներ