【发布时间】:2020-08-17 07:30:37
【问题描述】:
我正在尝试创建一个问答游戏,允许用户简单地单击图像作为答案。
我
function checkimage(){
}
body{
font: 15px/1.5 Arial, Helvetica,sans-serif;
padding:0;
margin:50px;
background-color:rgba(255, 128, 0, 0.54);
text-align: center
}
h2{
padding: 10px;
background-color: red;
}
#container{
margin : 20px auto;
background-color: white;
height: 60%;
width : 100%;
border-radius: 5px;
box-shadow: 0px 5px 15px 0px;
position: relative;
}
*{
box-sizing: border-box;
}
.column{
float:left;
width:100%;
padding:5px;
}
<!DOCTYPE html>
<html lang="en">
<meta name="viewport" content="width=device-width">
<head>
<meta charset="UTF-8">
<title>Quiz</title>
<link rel="stylesheet" href="game.css">
</head>
<body>
<h1> Welcome to the Shopping Quiz Game</h1>
<div id="container">
<div class = "question">
<h2>which of the following is a fruit? click on the image </h2>
<div class = "quiz">
<div class="column">
<input type="image" id="forest" src="forest.jpg" style="width:50%"> </div>
<input type="image" id="snow" src="snow.jpg" style="width:50%"
onclick="checkimage"> </div>
</div>
</div>
<div>
<script src="game.js"></script>
</div>
</body>
</html>
首先尝试将图像制作成按钮,因为它们是可点击的。但是,我有非常基本的 javascript 知识,我无法执行“点击”功能,一旦用户点击图像,程序会检查点击的图片是否是正确的答案,然后返回一条消息。
【问题讨论】:
-
如何知道正确答案?有api吗?
-
所以基本上有一个问题“哪个是苹果”,用户必须点击其中一张图片,一旦点击程序应该检查点击的图片是否对应正确的答案跨度>
标签: javascript image button onclick