Javascript 带有iCheck的单选按钮仅在确认返回true时更改值

Javascript 带有iCheck的单选按钮仅在确认返回true时更改值,javascript,jquery,icheck,Javascript,Jquery,Icheck,我用创建了现代单选按钮,有四个选项。当用户更改单选按钮时,我会弹出一条确认消息“确定吗?” 如果confirm return false,我想返回上一个单选按钮,但现在它不返回上一个单选按钮 这是代码的一部分: <form action="#" method="post"> <div style="padding-left:20px; line-height:2;"> <input type="radio" id="main-category1"

我用创建了现代单选按钮,有四个选项。当用户更改单选按钮时,我会弹出一条确认消息“确定吗?”

如果confirm return false,我想返回上一个单选按钮,但现在它不返回上一个单选按钮

这是代码的一部分:

<form action="#" method="post">
    <div style="padding-left:20px; line-height:2;">
      <input type="radio" id="main-category1" name="main-category" value="1" > 1. <br>
      <input type="radio" id="main-category2" name="main-category" value="2" > 2. <br>
      <input type="radio" id="main-category3" name="main-category" value="3" > 3. <br>
      <input type="radio" id="main-category4" name="main-category" value="4" > 4. <br>
      <input type="radio" id="main-category5" name="main-category" value="5" > 5. <br>
    </div>
  </form>

<scirpt>
$('input').on('ifClicked', function(event){        
   msg = confirm('Are you sure?');
   var cual= this;
   if(msg == false) {
       $('#main-category3').iCheck('check'); // It's check to new value and check to 3rd radio, but I want to check only 3rd radio. 
   }   
});
</script>

1. 
2.
3.
4.
5.
$('input')。在('ifClicked',函数(事件){ msg=confirm('你确定吗?'); var cual=这个; 如果(msg==false){ $(“#main-category3”).iCheck('check');//它是check to new value和check to third radio,但我只想检查第三个radio。 } });

$('input')。在('click',函数(事件){
msg=confirm('你确定吗?');
var cual=这个;
如果(msg==false){
$('#main-categoriy3').attr(“选中”,为真);
//这是检查到新值和检查到第三个收音机,但我只想检查第三个收音机。
}
});
我为你的代码创建了一个plunk并进行了更正


如果添加
返回false
,会发生什么情况?@JamesDonnelly;add return false-->如果单击
则不会发生此事件在iCheck插件中是有效的事件。@JamesDonnelly感谢您提供此信息。谢谢。“砰”的一声没有提到它。我现在添加它。
<script>
    $('input').on('click', function(event) {
      msg = confirm('Are you sure?');
      var cual = this;
      if (msg == false) {
        $('#main-category3').attr("checked",true);
        // It's check to new value and check to 3rd radio, but I want to check only 3rd radio. 
      }
    });
  </script>