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

时间:2015-05-20 11:06:24

标签: javascript jquery icheck

我使用iCheck创建现代单选按钮,有四个选项。当用户更改单选按钮时,我会弹出确认消息"您确定吗?"

如果确认返回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 个答案:

答案 0 :(得分:0)

<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>

我为你的代码创建了一个plunk并进行了修正

http://plnkr.co/edit/gist:1986619?p=preview