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 单选按钮确认的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
                问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转
                Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
                CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
                Ordinals in words javascript(javascript中的序数)
                getFullYear returns year before on first day of year(getFullYear 在一年的第一天返回前一年)
                • <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>