答案 0 :(得分:1)
您可以为图像设置display:block
img {
display: block;
padding-top: 5px;
}
var getAuthor = document.getElementById("authorImage");
function myAuthor(AuthorIndex)
{
getAuthor.style.display="";
if (AuthorIndex == 1)
{
getAuthor.src = "Stephen.jpg";
getAuthor.style.width = "300px";
getAuthor.style.height = "300px";
}
}
img {
display: block;
padding-top: 5px;
}
<select id="selectAuthor" onchange="myAuthor(this.value)">
<option value="0" onclick="">Please select an Author</option>
<option value="1">Stephen King</option>
<option value="2">George R. R. Martin</option>
<option value="3">Mark Twain</option>
</select>
<img src="" id="authorImage" width="300px" height="300px" align="top"/>
答案 1 :(得分:0)
<br/>
:
var getAuthor = document.getElementById("authorImage");
function myAuthor(AuthorIndex)
{
getAuthor.style.display="";
if (AuthorIndex == 1)
{
getAuthor.src = "Stephen.jpg";
getAuthor.style.width = "300px";
getAuthor.style.height = "300px";
}
}
<select id="selectAuthor" onchange="myAuthor(this.value)">
<option value="0" onclick="">Please select an Author</option>
<option value="1">Stephen King</option>
<option value="2">George R. R. Martin</option>
<option value="3">Mark Twain</option>
</select>
<br/>
<img src="" id="authorImage" width="300px" height="300px" align="top"/>
var getAuthor = document.getElementById("authorImage");
function myAuthor(AuthorIndex)
{
getAuthor.style.display="";
if (AuthorIndex == 1)
{
getAuthor.src = "Stephen.jpg";
getAuthor.style.width = "300px";
getAuthor.style.height = "300px";
}
}
.container {
width: 300px;
}
<div class="container">
<select id="selectAuthor" onchange="myAuthor(this.value)">
<option value="0" onclick="">Please select an Author</option>
<option value="1">Stephen King</option>
<option value="2">George R. R. Martin</option>
<option value="3">Mark Twain</option>
</select>
<img src="" id="authorImage" width="300px" height="300px" align="top"/>
</div>
display: block
属性:
var getAuthor = document.getElementById("authorImage");
function myAuthor(AuthorIndex)
{
getAuthor.style.display="";
if (AuthorIndex == 1)
{
getAuthor.src = "Stephen.jpg";
getAuthor.style.width = "300px";
getAuthor.style.height = "300px";
}
}
img { display: block; }
<select id="selectAuthor" onchange="myAuthor(this.value)">
<option value="0" onclick="">Please select an Author</option>
<option value="1">Stephen King</option>
<option value="2">George R. R. Martin</option>
<option value="3">Mark Twain</option>
</select>
<img src="" id="authorImage" width="300px" height="300px" align="top"/>