JavaScript图像(如何使用document.getElementById()设置高度和宽度。src=';';)
如何将布什图片设置为100px×100pxJavaScript图像(如何使用document.getElementById()设置高度和宽度。src=';';),javascript,Javascript,如何将布什图片设置为100px×100px <!DOCTYE html> <html> <head> <title> Title </title> <script> </script> </head> <body> <button type = button onclick = "docume
<!DOCTYE html>
<html>
<head>
<title> Title </title>
<script>
</script>
</head>
<body>
<button type = button onclick = "document.getElementById('myImage').src='bush.jpg'">Bush</button>
<button type = button onclick = "document.getElementById('myImage').src='obama.jpg'">Obama</button>
<p>Default is Obama </p>
<img id = "myImage" src = "obama.jpg" style = "width: 100px; height: 100px">
</body>
</html>
标题
灌木
奥巴马
默认的是奥巴马
我正处于学习javascript的开始阶段。不确定还需要哪些其他信息。我只是想找一份全栈web开发的工作,我意识到我在学校学到的(Java/C/C++)工作很少。我知道这是一个相对简单的问题,但也不知道如何用谷歌搜索答案,因为我不知道如何表达这个问题。。。哈任何有一定经验的人都知道如何做到这一点?您的样式属性中包含无效信息。您的图像标记如下所示:
<img id = "myImage" src = "obama.jpg" style = "width: 100px height: 100px">
<img id = "myImage" src = "obama.jpg" style = "width: 100px; height: 100px;">
你在
width:100px
Thank之后漏掉了一个分号-把Bush(按钮)改成200x200怎么样?@Gary-也许你应该在问你不知道怎么做的每件事之前单独学习。@Gary如果这解决了你的问题,你介意接受答案吗?