如何使用4个选项显示问题纸张(单选按钮选择选项) [英] How to display question Paper with 4 options(Radio Buttons to select the options)

查看:98
本文介绍了如何使用4个选项显示问题纸张(单选按钮选择选项)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨专家,



我正在做一个名为在线测试的小应用程序

这是从后面的代码中获取随机问题(通过ajax调用)并将其存储在java脚本数组中。



现在通过此代码在我的网页中逐个显示问题。

  var  questionToDisplay = questionArr [index]; 
document.getElementById( spnQuestion)。innerHTML = questionToDisplay.Question;
document.getElementById( spnOptionA)。innerHTML = questionToDisplay.OptionA;
document.getElementById( spnOptionB)。innerHTML = questionToDisplay.OptionB;
document.getElementById( spnOptionC)。innerHTML = questionToDisplay.OptionC;
document.getElementById( spnOptionD)。innerHTML = questionToDisplay.OptionD;





但它没有以正确的方式显示。这里我可以选择所有单选按钮。

和我的html设计是

< div  class  =   row> 
< span id = spnQuestion> < / span >
< / div >
< div < span class =code-keyword> class = row>
< input type = radio id = rdbOptionA />< span id = spnOptionA> < / span >
< / div >
< div class = row>
< input type = radio id = rdbOptionB />< span id = spnOptionB> < / span >
< / div >
< div class = row>
< input type = radio id = rdbOptionC />< span id = spnOptionC> < / span >
< / div >
< div class = row>
< input type = radio id = rdbOptionD />< span id = spnOptionD> < / span >
< / div >



任何人都可以告诉我显示这些选项的正确方法。



提前感谢

(Keerthi Kumar)

解决方案

相关的单选按钮必须具有通用名称属性将它们标识为一个组,并使用value属性为组中的每个单选按钮分配不同的值。参见示例:

http://www.w3schools.com/html/tryit .asp?filename = tryhtml_radio [ ^

Hi Experts,

Am doing a small application called Online Test
In this am getting the random questions from code behind (By ajax call) and storing it in the java script array.

Now am displaying the questions one by one in my web page by this code.

var questionToDisplay = questionArr[index];
             document.getElementById("spnQuestion").innerHTML=questionToDisplay.Question;
document.getElementById("spnOptionA").innerHTML = questionToDisplay.OptionA;
document.getElementById("spnOptionB").innerHTML = questionToDisplay.OptionB;
document.getElementById("spnOptionC").innerHTML = questionToDisplay.OptionC;
document.getElementById("spnOptionD").innerHTML = questionToDisplay.OptionD;



But it is not showing in a correct way. Here am able to select all the radio buttons.
and my html design is

<div class="row">
    <span id="spnQuestion"></span>
</div>
<div class="row">
  <input type="radio" id="rdbOptionA" /><span id="spnOptionA"></span>
</div>
<div class="row">
  <input type="radio" id="rdbOptionB" /><span id="spnOptionB"></span>
</div>
<div class="row">
 <input type="radio" id="rdbOptionC" /><span id="spnOptionC"></span>
</div>
<div class="row">
 <input type="radio" id="rdbOptionD" /><span id="spnOptionD"></span>
</div>


can any one please tell me a correct way to display these options.

thanks in advance
(Keerthi Kumar)

解决方案

Related radio buttons must have a common name attribute to identify them as a group, and use the value attribute to assign different value to each radio button in the group. see example:
http://www.w3schools.com/html/tryit.asp?filename=tryhtml_radio[^]


这篇关于如何使用4个选项显示问题纸张(单选按钮选择选项)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆