+ 3
What's wrong??
5 Réponses
+ 3
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<p id="p"></p>
<button onclick="a()">Change</button>
<script>
var f = "Sina"
var s = "Navid"
var grow = true;
function a(){
var x = document.getElementById("p")
if(grow){
x.innerHTML = f
}
else {
x.innerHTML = s;
}
if(x.innerHTML == f || x.innerHTML == s){
grow = !grow
}
}
</script>
</body>
</html>
+ 3
Ur using assignment operator in if condition
use equality operator insted
+ 3
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<p id="x"></p>
<button id="button">Change</button>
<script>
var f = "Sina"
var s = "Navid"
window.flag=false;
button.onclick=function() {
window.flag=!window.flag;
if (window.flag) {
x.innerHTML = f
}
else{
x.innerHTML = s;
}
};
</script>
</body>
</html>
+ 3
you can also use this easy to understand
+ 3
Thanks all