use*_*447 3 javascript image onclick
这似乎应该有效,但事实并非如此。我不确定问题出在哪里 - 要么我做错了,要么我可能有语法错误。我只是什么都不做。我试图在单击按钮时更改当前图片。我是 Javascript 的初学者,所以请温柔一点;)谢谢!
<html>
<script>
function pictureChange()
{
document.getElementById(theImage).src="http://31.media.tumblr.com/fca646cd8fe87906e605ad7e8d039903/tumblr_mmoz4fWT6U1soh1p8o1_500.png");
}
</script>
<body>
<img id="theImage" src="http://31.media.tumblr.com/18b5f8f0a00ad01e50f7ae2f513be52d/tumblr_msqcl4iwM01soh1p8o1_500.png">
<p><input type="button" id="theButton" value="click me!" onclick="pictureChange()"></p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
您错过了中的引号.getElementById('theImage')
function pictureChange()
{
document.getElementById('theImage').src="http://31.media.tumblr.com/fca646cd8fe87906e605ad7e8d039903/tumblr_mmoz4fWT6U1soh1p8o1_500.png";
}
Run Code Online (Sandbox Code Playgroud)