1. <i id='hpNSs'><tr id='hpNSs'><dt id='hpNSs'><q id='hpNSs'><span id='hpNSs'><b id='hpNSs'><form id='hpNSs'><ins id='hpNSs'></ins><ul id='hpNSs'></ul><sub id='hpNSs'></sub></form><legend id='hpNSs'></legend><bdo id='hpNSs'><pre id='hpNSs'><center id='hpNSs'></center></pre></bdo></b><th id='hpNSs'></th></span></q></dt></tr></i><div id='hpNSs'><tfoot id='hpNSs'></tfoot><dl id='hpNSs'><fieldset id='hpNSs'></fieldset></dl></div>
  2. <legend id='hpNSs'><style id='hpNSs'><dir id='hpNSs'><q id='hpNSs'></q></dir></style></legend>

  3. <tfoot id='hpNSs'></tfoot>

    <small id='hpNSs'></small><noframes id='hpNSs'>

        <bdo id='hpNSs'></bdo><ul id='hpNSs'></ul>
    1. JavaScript 单选按钮确认

      JavaScript radio button confirmation(JavaScript 单选按钮确认)

            <tbody id='2vpAl'></tbody>

          <small id='2vpAl'></small><noframes id='2vpAl'>

          • <legend id='2vpAl'><style id='2vpAl'><dir id='2vpAl'><q id='2vpAl'></q></dir></style></legend>
            <i id='2vpAl'><tr id='2vpAl'><dt id='2vpAl'><q id='2vpAl'><span id='2vpAl'><b id='2vpAl'><form id='2vpAl'><ins id='2vpAl'></ins><ul id='2vpAl'></ul><sub id='2vpAl'></sub></form><legend id='2vpAl'></legend><bdo id='2vpAl'><pre id='2vpAl'><center id='2vpAl'></center></pre></bdo></b><th id='2vpAl'></th></span></q></dt></tr></i><div id='2vpAl'><tfoot id='2vpAl'></tfoot><dl id='2vpAl'><fieldset id='2vpAl'></fieldset></dl></div>

            • <tfoot id='2vpAl'></tfoot>

              • <bdo id='2vpAl'></bdo><ul id='2vpAl'></ul>
              • 本文介绍了JavaScript 单选按钮确认的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在尝试向现有函数添加一个函数或附加 JavaScript 以进行确认.单击提交按钮后,我将需要一个确认框,上面写着您选择了(GCSE、A2 或 AS),这是正确的吗?"应该有一个取消按钮来返回表单或一个允许提交表单的 OK.

                I am trying to add a function, or additional JavaScript to the existing function for a confirmation. I will need a confirmation box once the submit button is clicked saying, "You have chosen (either GCSE, A2 or AS), is this correct?" There should be a cancel button to return to the form or an OK which lets the form be submitted.

                这是代码,我做了一些研究,上面说使用循环,我对此很陌生,所以我不知道该怎么做.

                Here is the code, I did a little research and it said use a loop, I am very new to this so I don't know what to do.

                <head>
                <title>Exam entry</title>
                <script language="javascript" type="text/javascript">
                
                function validateForm() {
                var result = true;
                var msg="";
                if (document.ExamEntry.name.value=="") {
                msg+="You must enter your name 
                ";
                document.ExamEntry.name.focus();
                document.getElementById('name').style.color="red";
                result = false;
                }
                
                if(msg==""){
                return result;
                }
                {
                alert(msg)
                return result;
                }
                }
                
                </script>
                </head>
                <body>
                <h1>Exam Entry Form</h1>
                <form name="ExamEntry" method="post" action="success.html">
                <table width="50%" border="0">
                <tr>
                <td id="name">Name</td>
                <td><input type="text" name="name" /></td>
                <tr>
                <td id="subject">Subject</td>
                <td><input type="text" name="subject" /></td>
                </tr>
                <tr>
                <td id="examnumber">Examination Number</td>
                <td><input type="text" name="examnumber" /></td>
                </tr>
                <tr>
                <td><input type="radio" id="examtype" name="examtype" /> : GCSE<br />
                <td><input type="radio" id="examtype" name="examtype"  /> : A2<br />
                <td><input type="radio" id="examtype" name="examtype" /> : AS<br />
                </tr>
                <tr>
                <td><input type="submit" name="Submit" value="Submit" onclick="return validateForm();"    />  </td>
                <td><input type="reset" name="Reset" value="Reset" /></td>
                </tr>
                </table>
                </form>
                </body>
                

                推荐答案

                像这样设置单选按钮的值:

                Set your radio buttons' values like this:

                <td><input type="radio" id="examtype" name="examtype" value="GCSE" /> : GCSE<br />
                <td><input type="radio" id="examtype" name="examtype" value="A2" /> : A2<br />
                <td><input type="radio" id="examtype" name="examtype" value="AS"/> : AS<br />
                

                然后在您的函数中使用此脚本来验证表单或使其成为一个函数并从您的函数 validateForm 中调用它:

                Then use this script in your function to validate form or make it a function and call it from your function validateForm:

                var checked = null;
                var inputs = document.getElementsByName('examtype');
                for (var i = 0; i < inputs.length; i++) {
                          if (inputs[i].checked) {
                           checked = inputs[i];
                           break;
                   }
                }
                if(checked==null)
                {
                    alert('Please choose an option');
                    return false;
                }
                else{
                    return confirm('You have chosen '+checked.value+' is this correct?');
                }
                

                这篇关于JavaScript 单选按钮确认的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Toggle HTML radio button by clicking its label(通过单击标签来切换 HTML 单选按钮)
                Javascript how to change radio button label text?(Javascript如何更改单选按钮标签文本?)
                How can I automatically select specific radio buttons with Greasemonkey?(如何使用 Greasemonkey 自动选择特定的单选按钮?)
                AngularJs. Is it possible to deselect HTML “radio” input by click?(AngularJs.是否可以通过单击取消选择 HTML“收音机输入?)
                Checking Value of Radio Button Group via JavaScript?(通过 JavaScript 检查单选按钮组的值?)
                getting selected value of radio button in case of action(在采取行动的情况下获取单选按钮的选定值)
                • <i id='IQgz3'><tr id='IQgz3'><dt id='IQgz3'><q id='IQgz3'><span id='IQgz3'><b id='IQgz3'><form id='IQgz3'><ins id='IQgz3'></ins><ul id='IQgz3'></ul><sub id='IQgz3'></sub></form><legend id='IQgz3'></legend><bdo id='IQgz3'><pre id='IQgz3'><center id='IQgz3'></center></pre></bdo></b><th id='IQgz3'></th></span></q></dt></tr></i><div id='IQgz3'><tfoot id='IQgz3'></tfoot><dl id='IQgz3'><fieldset id='IQgz3'></fieldset></dl></div>
                      <tbody id='IQgz3'></tbody>

                  • <small id='IQgz3'></small><noframes id='IQgz3'>

                    <tfoot id='IQgz3'></tfoot>

                      1. <legend id='IQgz3'><style id='IQgz3'><dir id='IQgz3'><q id='IQgz3'></q></dir></style></legend>
                        • <bdo id='IQgz3'></bdo><ul id='IQgz3'></ul>