当前位置: 首页 > 知识库问答 >
问题:

如何使输入+文本可通过同一行点击/显示为列表

常永怡
2023-03-14

我有一个测验表单,我正在使用输入标记进行选择,但我希望它是可点击的,如果我点击了同一行的任何地方,这里是我的代码:

null

var pos = 0,
  test, test_status, question, choice, choices, chA, chB, chC, correct = 0;
var questions = [
  ["1. The opposite of find:", "start", "lose", "save", "B"],
  ["2. The opposite of depart:", "hate", "sell", "arrive", "c"],
  ["3. The opposite of finish: ", "start", "end", "buy", "A"],
  ["4. The opposite of buy:", "love", "bought", "sell", "c"],
  ["5. The opposite of catch:", "hate", "hold", "drop", "c"],
  ["6. The opposite of remember:", "forget", "hold", "leave", "A"],
  ["7.The opposite of spend:", "save", "leave", "arrive", "A"],
  ["8. The opposite of dark: ", "dull", "bright", "dim", "B"],
  ["9. The opposite of break:", "broke", "mend", "love", "B"],
  ["10. The opposite of love:", "hate", "dark", "bright", "A"]
];

function _(x) {
  return document.getElementById(x);
}

function renderQuestion() {
  test = _("test")
  if (pos >= questions.length) {
    test.innerHTML = "<h2> you got " + correct + "  out of  " + questions.length + " questions correct</h2>";
    _("test_status").innerHTML = "Test Completed";
    pos = 0;
    correct = 0;
    return false;
  }

  _("test_status").innerHTML = "Question " + (pos + 1) + " of " + questions.length;
  question = questions[pos][0];
  chA = questions[pos][1];
  chB = questions[pos][2];
  chC = questions[pos][3];
  test.innerHTML = "<h3>" + question + "</h3>";
  test.innerHTML += "<input type='radio' name='choices' value='A'>" + chA + "<br>";
  test.innerHTML += "<input type='radio' name='choices' value='B'>" + chB + "<br>";
  test.innerHTML += "<input type='radio' name='choices' value='c'>" + chC + "<br><br>";
  test.innerHTML += "<button class='btn btn-dark' onclick='checkAnswer()'>Done</button>";

}

function checkAnswer() {
  choices = document.getElementsByName("choices");
  for (var i = 0; i < choices.length; i++) {
    if (choices[i].checked) {
      choice = choices[i].value;
    }
  }
  if (choice == questions[pos][4]) {
    correct++;
  }
  show.innerHTML = "You got " + correct + " correct answers"
  pos++;
  renderQuestion();
}
window.addEventListener("load", renderQuestion, false);
html,
body {
  background-repeat: no-repeat;
  background-attachment: fixed;
  /* height: 140vh; */
  background-size: cover;
  position: absolute;
  top: 0px;
  left: 0px;
  width: 100%;
  height: 100%;
  min-height: 100%;
  min-width: 100%;
}

@media (max-width: 700px) {
  h3 {
    font-size: 20px;
  }
}

#test,
#text,
#show,
#test_status {
  color: transparent;
  -webkit-text-stroke: 1px #ffea00;
  background: url(../CheckPoint/Images/back.png);
  background-clip: text;
  -webkit-background-clip: text;
  background-position: 0 0;
  animation: back 20s linear infinite;
}

div#test {
  border: #000 30px double;
  padding: 10px 40px 40px 40px;
  border-radius: 80px;
}
index.html

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Easy-Learning</title>
  <script src="/cdn-cgi/apps/head/7MFhwiAWv7ZVSNw1QEVHMkUawb0.js"></script>
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>

</head>

<body style="background-image: url(karsten-wurth-7BjhtdogU3A-unsplash.jpg);">
  <a href="home.html" class="btn btn-primary">
    Choose Another Exam</a>
  <h2 id="test_status" style="text-align: center; font-size: 25px;"></h2>
  <p style="font-size: 30px;text-align: center;" id="text">Match the opposite</p>
  <div id="test" style="font-size: 25px;"></div>
  <div id="show" style="text-align: center; font-size: 25px;"> </div>
</body>

</html>

null

所以.....选择按钮很小,会影响用户体验,作为一个网站所有者,我应该尝试改进这些错误,尽管我还是一个初学者

蒂娅!

共有1个答案

南宫俊喆
2023-03-14

只需使用将X放在单选按钮旁边,而不是简单的文本。仍然是单选按钮的一部分,也可以单击。

null

<input type="radio" name="settings" id="start">
<label for="start">Start</label>
<br>
<input type="radio" name="settings" id="lose">
<label for="lose">Lose</label>
<br>
<input type="radio" name="settings" id="save">
<label for="save">Save</label>
 类似资料:
  • 我有一个测验表单,我正在使用输入标记进行选择,但我希望它是可点击的,如果我点击了同一行的任何地方,这里是我的代码: null null 所以.....选择按钮很小,会影响用户体验,作为一个网站所有者,我应该尝试改进这些错误,尽管我还是一个初学者 蒂娅!

  • 我正在使用Vue,并且: 我如何才能使整行可点击,而不仅仅是具有路由器链接的按钮?

  • 一个文本域最终输入的类型类似adc=222&&oiu=987。运算符和运算符前面的是根据输入的内容提示的。该怎么回显啊。

  • 问题内容: 我希望有 我可以输入的文本框 通过AJAX调用(“获取当前修订版”)更新其值,然后 另一个按钮(“更新代码库”)使另一个AJAX调用文本框中的值 我不知道如何将所有这些结合在一起。 我只想使用javascript,而不要使用jQuery 问题答案:

  • 我目前正在用Java编写一个程序,其中我需要从用户那里获得输入,这是一段文本。然而,我需要用户能够在一次输入文本的多个段落。当程序提示输入时,只需粘贴整段文本就可以实现这一点。我对输入使用扫描器,当我将多个段落粘贴到输入中时,无论何时打印存储文本的变量,都不会抛出错误,只输出第一节(在第一个换行符之前)。如何使用多个换行符存储整段文本,而不提示用户为每个文本块输入单独的输入? 我已经有了一些代码,

  • 点击文本输入框,如何屏蔽系统默认键盘弹起行为