<legend id='PFSMu'><style id='PFSMu'><dir id='PFSMu'><q id='PFSMu'></q></dir></style></legend>

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

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

        • <bdo id='PFSMu'></bdo><ul id='PFSMu'></ul>

        Javascript/JQuery 取消选择单选按钮

        Javascript/ JQuery Deselecting radio buttons(Javascript/JQuery 取消选择单选按钮)
        <tfoot id='Lk944'></tfoot>
            <bdo id='Lk944'></bdo><ul id='Lk944'></ul>

                <tbody id='Lk944'></tbody>

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

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

                • <legend id='Lk944'><style id='Lk944'><dir id='Lk944'><q id='Lk944'></q></dir></style></legend>
                  本文介绍了Javascript/JQuery 取消选择单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有以下 javascript,我想使用它来使用户能够通过单击取消选择选定的单选按钮.(我知道这不是标准的,但是系统要求的:)

                  I have the following javascript, which I want to use to enable the user to deselect a selected radio button by clicking it. (I know this is not standard, but it is required by the system :)

                  DeselectRadioButton = {
                      setup: function () {
                          $(".deselectRadioButton").click(function () {
                              if ($(this).is(':checked')) {
                                  alert("I am checked!");
                                  ($(this).removeAttr('checked'));
                              }
                          });
                      }
                  };
                  

                  我的问题是,当我选择一个未选择的单选按钮时,它会在警报显示后立即取消选择它.

                  My issue is that when I select an unselected radio button, it immediately deselects it after the alert shows.

                  我想我是在项目更改后收到事件 - 如何修复此代码以使我的单选按钮无法选择?

                  I guess I am receiving the event after the item has changed - how can I fix this code to make my radio button deselectable?

                  谢谢!

                  推荐答案

                  但是,主要问题是当我选择一个未选中的单选按钮,它后立即取消选择它警报显示.

                  However, the main issue is that when I select an unselected radio button, it immediately deselects it after the alert shows.

                  您似乎无法使用 return falsee.preventDefault() 来阻止单选按钮的默认行为,因为单选按钮总是在点击处理程序被触发.解决此问题的一种方法是向单选按钮添加一个单独的类并将其用作您的指示器.

                  It seems you can't prevent the default behavior of a radio button with either return false or e.preventDefault() as the radio button always is checked when the click handler is fired. One way around this was to add a separate class to the radio button and use that as your indicator.

                  $(".deselectRadioButton").click( function(e){
                      if($(this).hasClass("on")){
                         $(this).removeAttr('checked');
                      }
                      $(this).toggleClass("on");
                  }).filter(":checked").addClass("on");
                  

                  jsfiddle 上的代码示例.

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

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

                  相关文档推荐

                  keeping radio buttons checked after form submit(表单提交后保持选中单选按钮)
                  Styling radio button - not work in IE and Firefox(样式单选按钮 - 在 IE 和 Firefox 中不起作用)
                  Toggle HTML radio button by clicking its label(通过单击标签来切换 HTML 单选按钮)
                  Javascript how to change radio button label text?(Javascript如何更改单选按钮标签文本?)
                  JavaScript radio button confirmation(JavaScript 单选按钮确认)
                  How can I automatically select specific radio buttons with Greasemonkey?(如何使用 Greasemonkey 自动选择特定的单选按钮?)
                  <tfoot id='OP24Y'></tfoot>

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

                            <legend id='OP24Y'><style id='OP24Y'><dir id='OP24Y'><q id='OP24Y'></q></dir></style></legend>
                              <tbody id='OP24Y'></tbody>