单选按钮不显示(android)

时间:2018-06-14 11:07:00

标签: javascript android cordova phonegap

我的应用程序显示患者的问卷。患者可以使用radiobutton选择答案。 radiobuttons显示在浏览器镶边中  与模拟器波纹,但不在应用程序(Android版本4.1.2)

HTML文件:

<body>

<div class ="h1"> Patientenfragebogen </div>

<form name = "question">

    <div class="question">
        <p id ="Question1"> </p>
        <div id="displayPossibleAnswers"> </div>
    </div>


    <div class="button">
        <button type="submit" id="weiter" onclick="saveAnswer()">Weiter</button>
    </div>

</form>

</body>

JS档案:

   for(i = 0; i < value.length; i++)
        {
            //add radiobuttons (q= "radio" ; value = contains chosen answer)
            $('#displayPossibleAnswers').append("<input id='radio" + i + "' type=" + q +" name='answer' value=" + value[i] +">");
            //add label and possible answers
            $('#displayPossibleAnswers').append("<label id='value" + i + "'>" + value[i] + "</label>");
            $('#displayPossibleAnswers').append("&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
        }

在模拟器中它看起来像这样(这应该是应用程序中的样子):

App Emulator

有谁知道我哪里错了?还有另一种可能性来显示单选按钮吗?

2 个答案:

答案 0 :(得分:0)

你走错了路。将您的Javascript和HTML代码更改为:

$(":radio").click(function () {
  	$("span").text($(":radio:checked").val());
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>

<div class ="h1"> Patientenfragebogen </div>

<form name = "question">

   <label for="inpt1_1">
      <input type="radio" id="inpt1_1" name="CheckBtn" value="testValue" /> with value
   </label><br>
    <label for="inpt1_2">
      <input type="radio" id="inpt1_2" name="CheckBtn" /> without value
    </label><br>
    the value is: <span></span>


    <div class="button">
        <button type="submit" id="weiter" onclick="saveAnswer()">Weiter</button>
    </div>

</form>

</body>

选中单选按钮后使用javascript /控制该值,或使用ajax调用。它就在你身上!

答案 1 :(得分:0)

我们解决了这个问题! :)

我们将js代码更改为:

for(var i = 0; i < answers[keyAnswer[counter]].length; i++)
{
    for(var j = 0; j < answers[keyAnswer[counter]][i].length; j++)
    {
        //display radiobuttons and labels
        document.getElementById("testForm").innerHTML += "<input id='radio" + j + "' type=" + q +" name='answer' value=" + answers[keyAnswer[counter]][i][j] +"/>  <label id='value" + j + "'>" + answers[keyAnswer[counter]][i][j] + "</label> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";

    }
}

它无需使用jquery就可以工作...

HTML文件:

<body>

<div class ="h1"> Patientenfragebogen </div>

<div class="question">
<form id= "testForm" name = "question">
<p id ="Question1"> </p>
<div id="displayPossibleAnswers">

</div>
</div>


<div class="button">
<button type="submit" id="weiter" onclick="saveAnswer()">Weiter</button>
</div>


</form>

</body>