首页 > 解决方案 > 提交按钮在 html 中不起作用,即使我给出了 onclick 元素

问题描述

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
 <script> 
     $(document).ready(function(){
        $("#btn1").click(function(){
                $(".btn1").show();
                $(".btn1").attr("disabled",true);
        });
    });
    function getanswer()
    {
        document.getElementById("useranswer").innerHTML = "";
        var e = document.getElementsByTagName('input');
        for(i = 0; i<= e.length ; i++)
        {
            if(e[i].type == 'radio')
            {
                if(e[i].checked)
                {
                    document.getElementById("useranswer").innerHTML += "Q" + e[i].name + "Answer you selected is :" + e[i].value+ "<br/>";
                }
            }
        }
    }
</script> 

这是以下 html 行的脚本代码

  <main class="questions">
        {% for Result in QUIZFORM %}
            <table>
                <br>
                <tr>
                    <td>{{Result.id}} ) {{Result.questions}}</td>
                </tr>
                <tr>
                    <td><input type="radio" id="choice1" name="{{Result.id}}" class="ans" value="{{Result.choice1}}">{{Result.choice1}}</td>
                </tr>
                <tr>
                    <td><input type="radio" id="choice1"   name="{{Result.id}}" class="ans" value="{{Result.choice2}}">{{Result.choice2}}</td>
                </tr>
                <tr>
                    <td><input type="radio" id="choice1"   name="{{Result.id}}" class="ans" value="{{Result.choice3}}">{{Result.choice3}}</td>
                </tr>
                <tr>
                    <td><input type="radio" id="choice1"   name="{{Result.id}}" class="ans" value="{{Result.choice4}}">{{Result.choice4}}</td>
                </tr>
                <tr>
                    <td><label id="correctanswer" class="ans" value="{{Result.correctanswer}}" style="display: none; color:green;">{{Result.correctanswer}}</label></td>
                </tr>
            </table>
            {% endfor %}
<input type="submit" value="submitanswer" id="btn1" onclick = " getanswer();" >

如果我单击它,提交按钮将不起作用。

任何人都可以帮我解决这个问题,这是怎么回事。每当单击提交答案时,它都不起作用。我期望的是:它应该跳转到 getanswer 函数并显示以下属性。请帮我解决一下这个。我正在使用 Django 框架。我正在使用此功能来验证用户的答案。谢谢你。

标签: javascripthtmldjango

解决方案


推荐阅读