有没有人知道如何在点击图像后将文字定位在图像上
我在下面附上了我希望如何显示的图片,
function showSpoiler(obj) {
var inner = obj.parentNode.getElementsByTagName("div")[0];
if (inner.style.display == "none")
inner.style.display = "";
else
inner.style.display = "none";
}

body,
input {
font-family: "Trebuchet ms", arial;
font-size: 0.9em;
color: #333;
position: absolute;
top: 1em;
}
.spoiler {}
.spoiler .inner {}

<div class="spoiler">
<img onclick="showSpoiler(this);" src="http://konpakuto.com/logo.jpg />
<div class="inner" style="display:none;">
This is a spoiler!
</div>
</div>
&#13;
答案 0 :(得分:1)
.spoiler {
background: black;
width: 100%;
position:relative;
}
.spoiler img {
margin-top: 60px;
background: black;
width: 100%;
}
.spoiler .inner {
font-size:20pt;
position:absolute;
color:white;
top:5px;
width:100%;
text-align:center;
}
var count=0;
function showSpoiler(obj) {
var inner = obj.parentNode.getElementsByTagName("div")[0];
if (count==0){
inner.textContent = "UNLOCK";
setTimeout(function(){inner.textContent = "";},2000);
count=1;
}
else{
inner.textContent = "LOCK";
setTimeout(function(){inner.textContent = "";},2000);
count=0;
}
}
body,
input {
font-family: "Trebuchet ms", arial;
font-size: 0.9em;
color: #333;
position: absolute;
top: 1em;
}
.spoiler {
background: black;
width: 100%;
position:relative;
}
.spoiler img {
margin-top: 60px;
background: black;
width: 100%;
}
.spoiler .inner {
font-size:20pt;
position:absolute;
color:white;
top:5px;
width:100%;
text-align:center;
}
<div class="spoiler">
<div class="inner">
LOCK
</div>
<img onclick="showSpoiler(this);" src="http://konpakuto.com/logo.jpg" />
</div>