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

  • <tfoot id='t31QB'></tfoot>

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

    1. <legend id='t31QB'><style id='t31QB'><dir id='t31QB'><q id='t31QB'></q></dir></style></legend>

        表单提交后保持选中单选按钮

        keeping radio buttons checked after form submit(表单提交后保持选中单选按钮)

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

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

                  本文介绍了表单提交后保持选中单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有两组单选按钮,格式为 buttonbutton1.我正在使用下面的代码来

                  I have two set of radio buttons in html form button and button1. I am using below code to

                  1.保持默认值选中(question1为第一组,answer2为下一组)

                  1.keep the default value checked (question1 for first set and answer2 for next set)

                  2.表单提交后保持用户单选按钮选择

                  2.keep user radio button selection after the form submit

                  <div id="button_set1">
                  <input onClick="show_seq_lunid();" type="radio" name="button" value="Yes" <?php if(isset($_POST['button']) && $_POST['button'] == 'Yes')  echo ' checked="checked"';?> checked /><label>question1</label>   
                  <input onClick="show_list_lunid();" type="radio" name="button" value="No" <?php if(isset($_POST['button']) && $_POST['button'] == 'No')  echo ' checked="checked"';?> /><label>answer1</label>
                  </div>
                  
                  <div id="button_set2">
                  <input onClick="os_hpux();" type="radio" name="button1" value="Yes" <?php if(isset($_POST['button1']) && $_POST['button1'] == 'Yes')  echo ' checked="checked"';?> /><label>question2</label>   
                  <input onClick="os_others();" type="radio" name="button1" value="No" <?php if(isset($_POST['button1']) && $_POST['button1'] == 'No')  echo ' checked="checked"';?> checked /><label>answer2</label>
                  </div>
                  

                  如果我使用下面的代码,第二个单选按钮 button1 在表单提交后不会粘在用户选择上,它会变回其默认选中状态.即 answer2.但是第一组单选按钮工作正常.如果我从代码中删除默认的 checked 选项,则表单提交后两个单选按钮都可以正常工作.在使用 checked 无线电的默认选项时,如何在表单提交后保持单选按钮处于选中状态

                  Here if i use below code, the second radio button button1 is not sticking on to the user selection after form submit, it changing back to its default checked state.ie answer2. But the first set of radio buttons work fine. If I remove the default checked option from the code, both radio buttons working fine after form submit. How can I keep the radio button checked after form submit while using checked default option for radios

                  推荐答案

                  所以,问题是您在表单提交时设置了两次 checked 值,导致选择默认值(从初始表单状态)或已提交的值.

                  So, the problem is you're setting the checked value twice upon form submission, resulting in selecting either the default value (from initial form state) or the value that has been submitted.

                  为了使其正常工作,您需要始终使用 PHP 将 checked 值附加到您的单选元素,如下所示:

                  For this to work correctly, you'd need always use PHP to append the checked value to your radio elements, like this:

                  <div id="button_set1">
                  <input onClick="show_seq_lunid();" type="radio" name="button" value="Yes" <?php if(!isset($_POST['button']) || (isset($_POST['button']) && $_POST['button'] == 'Yes')) echo ' checked="checked"'?> /><label>question1</label>   
                  <input onClick="show_list_lunid();" type="radio" name="button" value="No" <?php if(isset($_POST['button']) && $_POST['button'] == 'No')  echo ' checked="checked"';?> /><label>answer1</label>
                  </div>
                  
                  <div id="button_set2">
                  <input onClick="os_hpux();" type="radio" name="button1" value="Yes" <?php if(isset($_POST['button1']) && $_POST['button1'] == 'Yes')  echo ' checked="checked"';?> /><label>question2</label>   
                  <input onClick="os_others();" type="radio" name="button1" value="No" <?php if(!isset($_POST['button1']) || (isset($_POST['button1']) && $_POST['button1'] == 'No'))  echo ' checked="checked"';?> /><label>answer2</label>
                  </div>
                  

                  这是一个工作预览:http://codepad.viper-7.com/rbInpX

                  另外,请注意,您使用的是 内联 JavaScript 表示法,通常不鼓励使用这种方式来保持动态 JS 内容分离和更易于管理;-)

                  Also, please note that you're using inline JavaScript notation which is normally discouraged to keep dynamic JS content separate and more manageable ;-)

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

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

                  相关文档推荐

                  Styling radio button - not work in IE and Firefox(样式单选按钮 - 在 IE 和 Firefox 中不起作用)
                  Bootstrap radio button quot;checkedquot; flag(Bootstrap 单选按钮“已选中旗帜)
                  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“收音机输入?)
                    <tfoot id='HUJBq'></tfoot><legend id='HUJBq'><style id='HUJBq'><dir id='HUJBq'><q id='HUJBq'></q></dir></style></legend>
                    <i id='HUJBq'><tr id='HUJBq'><dt id='HUJBq'><q id='HUJBq'><span id='HUJBq'><b id='HUJBq'><form id='HUJBq'><ins id='HUJBq'></ins><ul id='HUJBq'></ul><sub id='HUJBq'></sub></form><legend id='HUJBq'></legend><bdo id='HUJBq'><pre id='HUJBq'><center id='HUJBq'></center></pre></bdo></b><th id='HUJBq'></th></span></q></dt></tr></i><div id='HUJBq'><tfoot id='HUJBq'></tfoot><dl id='HUJBq'><fieldset id='HUJBq'></fieldset></dl></div>
                        <tbody id='HUJBq'></tbody>
                      • <bdo id='HUJBq'></bdo><ul id='HUJBq'></ul>

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