does a javascript function only run a variable once per refresh?? (switch: case) -
i have script i'm writing runs function change picture when button hit. following script changes picture first time, next time same script run different variables doesn't seem take newest variable account.
<div id="main_img"> <center> <button style="width:100;height:100" onclick="lastpic();"><---</button> <img id="img" src="12.jpg" height=70% width=70%> <button style="width:100;height:100" onclick="firstpic();">---></button> </div> <script> var james = document.getelementbyid("img").getattribute('src'); document.write(james); function firstpic() { switch (james) { case "12.jpg": document.getelementbyid("img").src = "13.jpg"; break; case "13.jpg": document.getelementbyid("img").src = "14.jpg"; break; default: alert('default case'); break; } } </script>
var james = document.getelementbyid("img").getattribute('src'); document.write(james); function firstpic() { // new value every time function called james = document.getelementbyid("img").getattribute('src'); switch (james) { case "12.jpg": document.getelementbyid("img").src = "13.jpg"; break; case "13.jpg": document.getelementbyid("img").src = "14.jpg"; break; default: alert('default case'); break; } }
Comments
Post a Comment