我正在尝试练习我的编码。我创建了一个实验性网页。我的脸上有一张照片。我在下面放了一个按钮,通过将图像的显示属性设置为“无”来删除我的图片。但是,我尝试的任何东西似乎都没有用。为什么是这样?这是我的所有代码,因为我不知道问题可能在哪里。
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body
{
background-color: wheat;
}
.name:hover
{
background-color: aquamarine;
}
h1 {
width: 500px;
border: 20px outset brown;
padding: 20px;
background-color: gold;
color: goldenrod;
text-align: center;
margin: auto;
}
img {
height: 500px;
border: 2px solid black;
}
</style>
</head>
<body>
<h1>DENNIS MARKHAM'S FUNSITE</h1>
<br>
<p>Hi, this is <span class = "name"> Dennis</span>, and I'm creating this website just for fun. And
I guess for practice too.</p>
<p>As you can see, my name highlights when you scroll over it. Isn't that cool?
Well I think it is. </p>
<p>I think this could use a background image to give it a more...woody look.
But the problem is I don't understand shit about background images. That's a problem indeed.
</p>
<p>Oh well, let's do a picture:</p>
<br>
<img id = "me" src ='IMG_1742.jpg' alt='my face'>
<br>
<script type = "text/javascript">
function remove(){
document.getElementsById("me").style.display = "none";
//not sure why this doesn't work, but okay
}
</script>
<button type="button" OnClick="remove()">Remove Picture</button>
</body>
答案 0 :(得分:3)
那是getElementById
而非元素 s 。
答案 1 :(得分:0)
你还有一个“s”。试试:
document.getElementById("me")
答案 2 :(得分:0)
//这是答案。你说错了。 把这个代码记录下来.getElementById(&#34; me&#34;)。style.display =&#34; none&#34 ;;要替换你的代码,错误的单词是getElementById而不是getElementsById。得到了吗?