【发布时间】:2018-01-19 17:08:20
【问题描述】:
我正在处理一个 javascript 页面,当鼠标悬停在“显示信息”按钮上并按下回车键时,我希望在该页面上显示信息。我尝试了几种不同的方法,但我无法弄清楚出了什么问题。我很困惑,因为这是我一直在学习的课程,并且我按照说明进行操作,但不知何故我无法弄清楚我做错了什么。任何帮助和指导将不胜感激。
这是我的代码:
var content = document.getElementById("berriesContent");
var button = document.getElementById("showMoreBerries");
button.onclick = function BC() {
if (content.className == "open") {
content.className = "";
button.innerHTML = "Show Info";
} else {
content.className = "open";
button.innerHTML = "Hide Info";
}
};
function mouseinBerries() {
document.getElementById("showMoreBerries").style.background = "#001a33";
}
function mouseoutBerries() {
document.getElementById("showMoreBerries").style.background = " #1594e5";
}
document.keypress(function(e) {
if (e.which == 13) {
("#berriescontent").addClass("show");
}
})
body {
background-image: url(Photos/Books.jpg);
background-size: 75%;
background-position: center;
text-align: center;
font-family: "Lucida Console", Monaco, monospace;
}
#Main {
width: 100px;
height: 70px;
background: #f6e5b1;
margin: 25px auto;
border: #660000;
border-style: ridge;
border-width: 7px
}
img {
height: 275px;
}
#berriesContent {
width: 50%;
padding: 5px;
font-family: Sans-Serif;
font-size: 18px;
color: #444;
margin: 0 auto;
max-height: 0px;
overflow: hidden;
transition: max-height 0.01s;
}
#berriesContent.open {
max-height: 1000px;
background-color: burlywood;
transition: max-height 0.01s;
}
#showMoreBerries {
width: 20%;
background: #1594e5;
color: #fff;
font-family: sans-serif;
display: block;
cursor: pointer;
text-align: center;
padding: 15px;
margin: 10px auto;
}
<body bgcolor="#ff6633">
<div id="Main">
<h1> Menu</h1>
</div>
<center>
<div id="berriesPic">
<img src="photos/berries.jpg"><img></div>
<a id="showMoreBerries" onmouseover="mouseinBerries()" onmouseout="mouseoutBerries()">Show Info</a>
</center>
<div id=b erriesContent>
<p>This is the first photo I took after receiving a camera from my Grandfather.I was playing around with the settings and really loved the way that this photo in particular turned out. The red color against the more muted background stood out to me.</p>
</div>
</body>
【问题讨论】:
标签: javascript function show-hide keypress onkeypress